Home » All » Order of Preference Output Display Format in MATLAB

Order of Preference Output Display Format in MATLAB

Order of Preference  Output Display Format in MATLAB

In this section, discussed about Order of Preference  Output Display Format in MATLAB

Subscribe to Thesis123 YouTube Channel for Free and Latest Videos

Order of preference

1. Parenthesis-(),{},[]-In nested arithmetic operations, the innermost one of the parenthesis is executed
2. Exponentiation-(^)
3. Multiplication (*) or division (/, $$ (equal precedence)
4. Addition (+) or Subtraction (-)

Note:
In an expression higher precedence operations are executed before the lower precedence.
If the expression having more equal operations, the expressions are executed from the left to right.

>> 5+6/2
ans =     8
>> (5+6)/2
ans =   5.5000
>> 2+4/2+5
ans =     9
>> 2^3/2
ans =     4
>> 27^(1/3)+32^0.2
ans =     5
>> 27^1/3+32^0.2
ans =   11 

YOUR TURN

Calculate the value of 0.7854-(0.7854)^3/(1*2*3)+0.785^5/(1*2*3*4*5) …-0.785^7/(1*2*3*4*5*6*7)
>> 0.7854-(0.7854)^3/(1*2*3)+0.785^5/(1*2*3*4*5) ...-0.785^7/(1*2*3*4*5*6*7)ans =   0.7071

Basic Arithmetic Operations PART-B

Output display format/ Representation of Numbers

We can control the output display in command window or in printing file by using the command format. Different types of formats are available in the MATLAB and are given in Table

Floating-point numbers may be entered as either integer, decimal floating-point numbers, or using the or using the e notation:
>> 3
ans =     3
>> 3253235.23
ans =     3.2532e+06
>> 32.2523e-3
ans =   0.0323 

Note that the input does not necessarily reflect on the way the number is displayed.
If the largest number in a matrix would be written using the e notation, the appropriate multiple of 10 is taken outside of matrix:

>> [225323.23 523.23]
ans =   1.0e+05 *  2.2542  0.0052
>> [3.2376 9.2534e-7]
ans =   3.2376   0.0000
>> [728, 725324547]
ans =   1.0e+10 *    0.0000     7.2532

There are a number of formats as shown in Table  in which you can use to display the results. You may invoke any of the formats by typing format  ****,  where **** is the format.

Note: that there are no parentheses.

Table (3)

Name Description Comments and examples
short Scaled fixed point format with 5 digits. Default
Scaled fixed point format, with 4 digits after the decimal point. For example, 3.1416.
long Scaled fixed point format with 15 digits. full precision in decimal format
Scaled fixed point format with 14 to 15 digits after the decimal point for double; and 7 digits after the decimal point for single. For example, 3.141592653589793.
short e Floating point format with 5 digits. Floating point format, with 4 digits after the decimal point. For example, 3.1416e+000.
long e Floating point format with 15 digits. Floating point format, with 14 to 15 digits after the decimal point for double; and 7 digits after the decimal point for single. For example, 3.141592653589793e+000.
short g Best of fixed or floating point format with 5 digits. Best of fixed or floating point, with 4 digits after the decimal point. For example, 3.1416.
short eng Engineering format that has 4 digits after the decimal point, and a power that is a multiple of three. For example, 3.1416e+000.
long eng Engineering format that has exactly 16 significant digits and a power that is a multiple of three. For example, 3.14159265358979e+000.
compact Suppresses excess line feeds to show more output in a single screen. Contrast with loose. theta = pi/2
theta =
1.5708
loose Adds linefeeds to make output more readable. Contrast with compact. theta = pi/2
theta =
1.5708
hex Hexadecimal fomrat. Hexadecimal (hexadecimal representation of a binary double-precision number).
For example, 400921fb54442d18
+ The symbols +, - and blank are printed for positive, negative, and zero elements. Imaginary parts are ignored. For >>x=[1 -2 5]
>>x=
+-+
bank Fixed formats for rupees and pise For example, 3.14
rat Approximation by ratio of small integers. For example, 355/113

 Example

X=[4/3 1.2345e-6 pi]
>> format short
X =
1.3333   0.0000   3.1416
>> format long
X =
1.33333333333333   0.00000123450000   3.14159265358979
>> format short e
X =
1.3333e+000 1.2345e-006 3.1416e+000
>> format long e
X =
Columns 1 through 2
1.333333333333333e+000   1.234500000000000e-006

Column 3
3.141592653589793e+000
>> format short g
>> X
X =
1.3333 1.2345e-006       3.1416
>> format long g
>> X
X =
Columns 1 through 2
1.33333333333333               1.2345e-006
Column 3
3.14159265358979
>> format rat
>> X
X =
4/3         1/810045   355/113
>> format bank
>> X
X =
1.33         0.00         3.14
>> format compact
>> X
X =
1.3333   0.0000   3.1416
>> format loose
>> X
X =
1.3333   0.0000   3.1416
>> format +
>> X
X =
+++
>> format hex
>> X
X =
3ff5555555555555   3eb4b6231abfd271   400921fb54442d18

Subscribe to Thesis123 YouTube Channel for Free and Latest Videos