clear all

4/3

 

ans =

 

       4/3    

 

format

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 <a href="matlab:help disp">disp</a>, <a href="matlab:help display">display</a>, <a href="matlab:help isnumeric">isnumeric</a>, <a href="matlab:help isfloat">isfloat</a>, <a href="matlab:help isinteger">isinteger</a>.

 

    Reference page in Help browser

       <a href="matlab:doc format">doc format</a>

 

4/3

 

ans =

 

    1.3333

 

4+3*3

 

ans =

 

    13

 

(4+3)*3

 

ans =

 

    21

 

2^2

 

ans =

 

     4

 

12^3

 

ans =

 

        1728

 

3^12

 

ans =

 

      531441

 

exp(1)

 

ans =

 

    2.7183

 

sin(90)

 

ans =

 

    0.8940

 

sin(pi/2)

 

ans =

 

     1

 

pi

 

ans =

 

    3.1416

 

sin(pi)

 

ans =

 

  1.2246e-016

 

cos(pi)

 

ans =

 

    -1

 

tan(pi/4)

 

ans =

 

    1.0000

 

a=-1

 

a =

 

    -1

 

b=exp(22)

 

b =

 

  3.5849e+009

 

b=exp(22);

b

 

b =

 

  3.5849e+009

 

a

 

a =

 

    -1

 

c=a*b;

c

 

c =

 

 -3.5849e+009

 

whos

  Name      Size            Bytes  Class     Attributes

 

  a         1x1                 8  double             

  ans       1x1                 8  double             

  b         1x1                 8  double             

  c         1x1                 8  double             

 

ans

 

ans =

 

    1.0000

 

clear all

whos

A=[ 1 2; 3,4]

 

A =

 

     1     2

     3     4

 

B=[1 2 3; 12 4]

??? Error using ==> vertcat

CAT arguments dimensions are not consistent.

 

B=[-1 3;3 1]

 

B =

 

    -1     3

     3     1

 

A

 

A =

 

     1     2

     3     4

 

A+B

 

ans =

 

     0     5

     6     5

 

A-B

 

ans =

 

     2    -1

     0     3

 

2*A+3*B

 

ans =

 

    -1    13

    15    11

 

A*B

 

ans =

 

     5     5

     9    13

 

B*A

 

ans =

 

     8    10

     6    10

 

A/B

 

ans =

 

    0.5000    0.5000

    0.9000    1.3000

 

inv(B)

 

ans =

 

   -0.1000    0.3000

    0.3000    0.1000

 

A*ans

 

ans =

 

    0.5000    0.5000

    0.9000    1.3000

 

inv(A)*B

 

ans =

 

    5.0000   -5.0000

   -3.0000    4.0000

 

A\B

 

ans =

 

    5.0000   -5.0000

   -3.0000    4.0000

 

clear all

A=[1 2 2; 2 2 2]

 

A =

 

     1     2     2

     2     2     2

 

B=[1 2;3 4; 4 6]

 

B =

 

     1     2

     3     4

     4     6

 

A*B

 

ans =

 

    15    22

    16    24

 

B*A

 

ans =

 

     5     6     6

    11    14    14

    16    20    20

 

inv(A)

??? Error using ==> inv

Matrix must be square.

 

C=B*A;

C

 

C =

 

     5     6     6

    11    14    14

    16    20    20

 

clear all

A={1 2 3;5 -1 2; 3 -1 3]

??? A={1 2 3;5 -1 2; 3 -1 3]

                           |

Error: Unbalanced or unexpected parenthesis

or bracket.

 

A=[1 2 3;5 -1 2; 3 -1 3]

 

A =

 

     1     2     3

     5    -1     2

     3    -1     3

 

x=[2;-3;1]

 

x =

 

     2

    -3

     1

 

A*x

 

ans =

 

    -1

    15

    12

 

x*A

??? Error using ==> mtimes

Inner matrix dimensions must agree.

 

x'*A

 

ans =

 

   -10     6     3

 

x'

 

ans =

 

     2    -3     1

 

[V,lambda]=eig(A)

 

V =

 

    0.5503   -0.6093   -0.5086

   -0.7538   -0.6234   -0.7345

   -0.3591   -0.4899    0.4492

 

 

lambda =

 

   -3.6973         0         0

         0    5.4585         0

         0         0    1.2387

 

x=1:1:3

 

x =

 

     1     2     3

 

1:1:10

 

ans =

 

  Columns 1 through 7

 

     1     2     3     4     5     6     7

 

  Columns 8 through 10

 

     8     9    10

 

y=2:2:20

 

y =

 

  Columns 1 through 7

 

     2     4     6     8    10    12    14

 

  Columns 8 through 10

 

    16    18    20

 

size(x)

 

ans =

 

     1     3

 

x=1:1:10

 

x =

 

  Columns 1 through 7

 

     1     2     3     4     5     6     7

 

  Columns 8 through 10

 

     8     9    10

 

size(x)

 

ans =

 

     1    10

 

size(y)

 

ans =

 

     1    10

 

x.*y

 

ans =

 

  Columns 1 through 7

 

     2     8    18    32    50    72    98

 

  Columns 8 through 10

 

   128   162   200

 

x+y

 

ans =

 

  Columns 1 through 7

 

     3     6     9    12    15    18    21

 

  Columns 8 through 10

 

    24    27    30

 

x/y

 

ans =

 

    0.5000

 

x./y

 

ans =

 

  Columns 1 through 4

 

    0.5000    0.5000    0.5000    0.5000

 

  Columns 5 through 8

 

    0.5000    0.5000    0.5000    0.5000

 

  Columns 9 through 10

 

    0.5000    0.5000

 

sin(x)

 

ans =

 

  Columns 1 through 4

 

    0.8415    0.9093    0.1411   -0.7568

 

  Columns 5 through 8

 

   -0.9589   -0.2794    0.6570    0.9894

 

  Columns 9 through 10

 

    0.4121   -0.5440

 

exp(y)

 

ans =

 

  1.0e+008 *

 

  Columns 1 through 4

 

    0.0000    0.0000    0.0000    0.0000

 

  Columns 5 through 8

 

    0.0002    0.0016    0.0120    0.0889

 

  Columns 9 through 10

 

    0.6566    4.8517

 

help plot

 PLOT   Linear plot.

    PLOT(X,Y) plots vector Y versus vector X. If X or Y is a matrix,

    then the vector is plotted versus the rows or columns of the matrix,

    whichever line up.  If X is a scalar and Y is a vector, disconnected

    line objects are created and plotted as discrete points vertically at

    X.

 

    PLOT(Y) plots the columns of Y versus their index.

    If Y is complex, PLOT(Y) is equivalent to PLOT(real(Y),imag(Y)).

    In all other uses of PLOT, the imaginary part is ignored.

 

    Various line types, plot symbols and colors may be obtained with

    PLOT(X,Y,S) where S is a character string made from one element

    from any or all the following 3 columns:

 

           b     blue          .     point              -     solid

           g     green         o     circle             :     dotted

           r     red           x     x-mark             -.    dashdot

           c     cyan          +     plus               --    dashed  

           m     magenta       *     star             (none)  no line

           y     yellow        s     square

           k     black         d     diamond

           w     white         v     triangle (down)

                               ^     triangle (up)

                               <     triangle (left)

                               >     triangle (right)

                               p     pentagram

                               h     hexagram

                         

    For example, PLOT(X,Y,'c+:') plots a cyan dotted line with a plus

    at each data point; PLOT(X,Y,'bd') plots blue diamond at each data

    point but does not draw any line.

 

    PLOT(X1,Y1,S1,X2,Y2,S2,X3,Y3,S3,...) combines the plots defined by

    the (X,Y,S) triples, where the X's and Y's are vectors or matrices

    and the S's are strings. 

 

    For example, PLOT(X,Y,'y-',X,Y,'go') plots the data twice, with a

    solid yellow line interpolating green circles at the data points.

 

    The PLOT command, if no color is specified, makes automatic use of

    the colors specified by the axes ColorOrder property.  The default

    ColorOrder is listed in the table above for color systems where the

    default is blue for one line, and for multiple lines, to cycle

    through the first six colors in the table.  For monochrome systems,

    PLOT cycles over the axes LineStyleOrder property.

 

    If you do not specify a marker type, PLOT uses no marker.

    If you do not specify a line style, PLOT uses a solid line.

 

    PLOT(AX,...) plots into the axes with handle AX.

 

    PLOT returns a column vector of handles to lineseries objects, one

    handle per plotted line.

 

    The X,Y pairs, or X,Y,S triples, can be followed by

    parameter/value pairs to specify additional properties

    of the lines. For example, PLOT(X,Y,'LineWidth',2,'Color',[.6 0 0])

    will create a plot with a dark red line width of 2 points.

 

    Example

       x = -pi:pi/10:pi;

       y = tan(sin(x)) - sin(tan(x));

       plot(x,y,'--rs','LineWidth',2,...

                       'MarkerEdgeColor','k',...

                       'MarkerFaceColor','g',...

                       'MarkerSize',10)

 

    See also <a href="matlab:help plottools">plottools</a>, <a href="matlab:help semilogx">semilogx</a>, <a href="matlab:help semilogy">semilogy</a>, <a href="matlab:help loglog">loglog</a>, <a href="matlab:help plotyy">plotyy</a>, <a href="matlab:help plot3">plot3</a>, <a href="matlab:help grid">grid</a>,

    <a href="matlab:help title">title</a>, <a href="matlab:help xlabel">xlabel</a>, <a href="matlab:help ylabel">ylabel</a>, <a href="matlab:help axis">axis</a>, <a href="matlab:help axes">axes</a>, <a href="matlab:help hold">hold</a>, <a href="matlab:help legend">legend</a>, <a href="matlab:help subplot">subplot</a>, <a href="matlab:help scatter">scatter</a>.

 

    Overloaded methods:

       <a href="matlab:help timeseries/plot">timeseries/plot</a>

       <a href="matlab:help channel.plot">channel.plot</a>

       <a href="matlab:help cfit/plot">cfit/plot</a>

       <a href="matlab:help idmodel/plot">idmodel/plot</a>

       <a href="matlab:help idfrd/plot">idfrd/plot</a>

       <a href="matlab:help iddata/plot">iddata/plot</a>

       <a href="matlab:help idnlhw/plot">idnlhw/plot</a>

       <a href="matlab:help idnlarx/plot">idnlarx/plot</a>

       <a href="matlab:help frd/plot">frd/plot</a>

       <a href="matlab:help dspdata.plot">dspdata.plot</a>

       <a href="matlab:help wdectree/plot">wdectree/plot</a>

       <a href="matlab:help ntree/plot">ntree/plot</a>

       <a href="matlab:help dtree/plot">dtree/plot</a>

       <a href="matlab:help wvtree/plot">wvtree/plot</a>

       <a href="matlab:help rwvtree/plot">rwvtree/plot</a>

       <a href="matlab:help edwttree/plot">edwttree/plot</a>

 

    Reference page in Help browser

       <a href="matlab:doc plot">doc plot</a>

 

doc plot

 Overloaded functions or methods (ones with the same name in other directories)

   <a href="matlab:doc simulink/plot">doc simulink/plot</a>

   <a href="matlab:doc curvefit/plot">doc curvefit/plot</a>

   <a href="matlab:doc fixedpoint/plot">doc fixedpoint/plot</a>

   <a href="matlab:doc ident/plot">doc ident/plot</a>

   <a href="matlab:doc wavelet/plot">doc wavelet/plot</a>

 

x=0:0.1:2*pi

 

x =

 

  Columns 1 through 4

 

         0    0.1000    0.2000    0.3000

 

  Columns 5 through 8

 

    0.4000    0.5000    0.6000    0.7000

 

  Columns 9 through 12

 

    0.8000    0.9000    1.0000    1.1000

 

  Columns 13 through 16

 

    1.2000    1.3000    1.4000    1.5000

 

  Columns 17 through 20

 

    1.6000    1.7000    1.8000    1.9000

 

  Columns 21 through 24

 

    2.0000    2.1000    2.2000    2.3000

 

  Columns 25 through 28

 

    2.4000    2.5000    2.6000    2.7000

 

  Columns 29 through 32

 

    2.8000    2.9000    3.0000    3.1000

 

  Columns 33 through 36

 

    3.2000    3.3000    3.4000    3.5000

 

  Columns 37 through 40

 

    3.6000    3.7000    3.8000    3.9000

 

  Columns 41 through 44

 

    4.0000    4.1000    4.2000    4.3000

 

  Columns 45 through 48

 

    4.4000    4.5000    4.6000    4.7000

 

  Columns 49 through 52

 

    4.8000    4.9000    5.0000    5.1000

 

  Columns 53 through 56

 

    5.2000    5.3000    5.4000    5.5000

 

  Columns 57 through 60

 

    5.6000    5.7000    5.8000    5.9000

 

  Columns 61 through 63

 

    6.0000    6.1000    6.2000

 

y=sin(x);

plot(x,y)

axis tight

hold

Current plot held

plot(x,cos(x))

 

plot(x,sin(x),'--',x,cos(x),'.-')

legend('sin','cos')

clear all

x=linspace(-1,1,200);

y=x;

[X,Y]=meshgrid(x,y);

size(X)

 

ans =

 

   200   200

 

R2=X.^2+Y.^2;

z=cos(3*pi*X.*Y).*exp(-2*R2)+sin(X.*Y);

mesh(x,y,z);

surf(x,y,z)

shading interp, light

axis off

colormap winter

diary