x := 5
{??? Error: "x" was previously used as a variable,
conflicting with its use here as the name of a function or command.
See MATLAB Programming, "How MATLAB Recognizes Function Calls That
Use Command Syntax" for details.
}
x = [1 2 3]
x =
1 2 3
x [123]
{??? Error: "x" was previously used as a variable,
conflicting with its use here as the name of a function or
command.
See MATLAB Programming, "How MATLAB Recognizes Function Calls That
Use Command Syntax" for details.
}
x = [123]
x =
123
x = [1,2,3]
x =
1 2 3
x = [1 2,3 , 5, , 5]
??? x = [1 2,3 , 5, , 5]
|
{Error: Expression or statement is incorrect--possibly unbalanced (,
{, or [.
}
x = [1 2,3 , 5, 5, 5]
x =
1 2 3 5 5 5
x=5
x =
5
x =5
x =
5
x=5,y = 7
x =
5
y =
7
x=5;
x
x =
5
x=34;
x
x =
34
x=y
x =
7
x==y
ans =
1
namelengthmax
ans =
63
marge_simpson = 45
marge_simpson =
45
marge_simpson = 'big blue hair'
marge_simpson =
big blue hair
sqrt(3)
ans =
1.7321
sqrt = 5
sqrt =
5
sqrt(3)
{??? Index exceeds matrix dimensions.
}
clear sqrt
sqrt(3)
ans =
1.7321
sin(.03)
ans =
0.029996
sin(pi)
ans =
1.2246e-016
cos(0)
ans =
1
format long
cos(0)
ans =
1
format g
{??? Error using ==> format
Unknown command option.
}
sin(.03)
ans =
0.029995500202496
format short
sin(.03)
ans =
0.0300
help format
FORMAT Set output format.
FORMAT with no inputs sets the output format to the default appropriate
for the class of the variable. For float variables, the default is
FORMAT SHORT.
FORMAT does not affect how MATLAB computations are done. Computations
on float variables, namely single or double, are done in appropriate
floating point precision, no matter how those variables are displayed.
Computations on integer variables are done natively in integer. Integer
variables are always displayed to the appropriate number of digits for
the class, for example, 3 digits to display the INT8 range -128:127.
FORMAT SHORT and LONG do not affect the display of integer variables.
FORMAT may be used to switch between different output display formats
of all float variables as follows:
FORMAT SHORT Scaled fixed point format with 5 digits.
FORMAT LONG Scaled fixed point format with 15 digits for double
and 7 digits for single.
FORMAT SHORT E Floating point format with 5 digits.
FORMAT LONG E Floating point format with 15 digits for double and
7 digits for single.
FORMAT SHORT G Best of fixed or floating point format with 5
digits.
FORMAT LONG G Best of fixed or floating point format with 15
digits for double and 7 digits for single.
FORMAT SHORT ENG Engineering format that has at least 5 digits
and a power that is a multiple of three
FORMAT LONG ENG Engineering format that has exactly 16 significant
digits and a power that is a multiple of three.
FORMAT may be used to switch between different output display formats
of all numeric variables as follows:
FORMAT HEX Hexadecimal format.
FORMAT + The symbols +, - and blank are printed
for positive, negative and zero elements.
Imaginary parts are ignored.
FORMAT BANK Fixed format for dollars and cents.
FORMAT RAT Approximation by ratio of small integers. Numbers
with a large numerator or large denominator are
replaced by *.
FORMAT may be used to affect the spacing in the display of all
variables as follows:
FORMAT COMPACT Suppresses extra line-feeds.
FORMAT LOOSE Puts the extra line-feeds back in.
Example:
format short, pi, single(pi)
displays both double and single pi with 5 digits as 3.1416 while
format long, pi, single(pi)
displays pi as 3.141592653589793 and single(pi) as 3.1415927.
format, intmax('uint64'), realmax
shows these values as 18446744073709551615 and 1.7977e+308 while
format hex, intmax('uint64'), realmax
shows them as ffffffffffffffff and 7fefffffffffffff respectively.
The HEX display corresponds to the internal representation of the value
and is not the same as the hexadecimal notation in the C programming
language.
See also disp, display, isnumeric, isfloat, isinteger.
Overloaded methods:
quantizer/format
Reference page in Help browser
doc format
format long g
sin(.03)
ans =
0.0299955002024957
format long g
plus(3,4)
ans =
7
3+4
ans =
7
divide(3,4)
{??? Undefined function or method 'divide' for input arguments of
type 'double'.
}
divide(120/4)
{??? Input argument "bottom" is undefined.
Error in ==> divide at 2
a = top/bottom;}
divide(120,4)
ans =
30
divide(120,4)
{??? Error: File: divide.m Line: 2 Column: 9
Unexpected MATLAB expression.
}
divide(120,4)
ans =
30
divide(120,4)
a =
30
ans =
30
ans
ans =
30
clc
ans
ans =
30
x = divide(121,3)
x =
40.3333333333333
whos
Name Size Bytes Class Attributes
ans 1x1 8 double
answer 1x143 286 char
button 1x3 6 char
eventdata 0x0 0 double
hObject 1x1 8 double
handles 1x1 1452 struct
last_dir_489231315124 1x105 210 char
marge_simpson 1x13 26 char
varargin 0x0 0 cell
x 1x1 8 double
y 1x1 8 double
clear
x = divide(121,3)
x =
40.3333333333333
whos
Name Size Bytes Class Attributes
x 1x1 8 double
M = [1 2 3; 3, -4 pi]
M =
Columns 1 through 2
1 2
3 -4
Column 3
3
3.14159265358979
M
M =
Columns 1 through 2
1 2
3 -4
Column 3
3
3.14159265358979
format short
M
M =
1.0000 2.0000 3.0000
3.0000 -4.0000 3.1416
M = [1 2 3; 3, -4 pi]
M =
1.0000 2.0000 3.0000
3.0000 -4.0000 3.1416
M(1,2)
ans =
2
M(1,3)
ans =
3
M(1,end)
ans =
3
M(end,end)
ans =
3.1416
diary off