Tuesday 1, Apr 2025

Adsense

Translate the website into your language :)

Latest News

    Powered by Blogger.
    Himadri

    MATLAB basic commands for beginners

    After starting MATLAB you can see a command window, here you can write basic commands, some commands are given below:

    >> x=[1 2 3 4 5]

    x =

         1     2     3     4     5

    >> y=5*x

    y =

         5    10    15    20    25

    >> y1=max(y)

    y1 =

        25

    >> [y1,y2]=may y
     [y1,y2]=may y
                |
    Error: Unexpected MATLAB expression.

    >> [y1,y2]=max y
     [y1,y2]=max y
                |
    Error: Unexpected MATLAB expression.

    >> [y1,y2]=max(y)

    y1 =

        25


    y2 =

         5

    >> [y1,y2]=max(y1)

    y1 =

        25


    y2 =

         1

    >> x=[1 2 3 4 6 5 7 8 9.9 1 8 9 5 2 3 4]

    x =

      Columns 1 through 9

        1.0000    2.0000    3.0000    4.0000    6.0000    5.0000    7.0000    8.0000    9.9000

      Columns 10 through 16

        1.0000    8.0000    9.0000    5.0000    2.0000    3.0000    4.0000

    >> y33=3.5>x

    y33 =

      Columns 1 through 15

         1     1     1     0     0     0     0     0     0     1     0     0     0     1     1

      Column 16

         0

    >>
    >> y5=x(1:4)

    y5 =

         1     2     3     4

    >> y5=x(4:1)

    y5 =

       Empty matrix: 1-by-0

    >>
    >> a=1:5

    a =

         1     2     3     4     5

    >> x=1:2:10

    x =

         1     3     5     7     9

    >> x=1:2:12

    x =

         1     3     5     7     9    11

    >> x=1:2:20

    x =

         1     3     5     7     9    11    13    15    17    19

    >> g=1 2 3;4 5 6;7 8 9
     g=1 2 3;4 5 6;7 8 9
        |
    Error: Unexpected MATLAB expression.

    >> g=[1 2 3;4 5 6;7 8 9]

    g =

         1     2     3
         4     5     6
         7     8     9

    >> g(:,3)

    ans =

         3
         6
         9

    >> g(,:3)
     g(,:3)
      |
    Error: Expression or statement is incorrect--possibly unbalanced (, {, or [.

    >> g(:,3)

    ans =

         3
         6
         9

    >> g(3:,)
     g(3:,)
        |
    Error: Expression or statement is incorrect--possibly unbalanced (, {, or [.

    >> g(3,:)

    ans =

         7     8     9

    >> g(:,2)

    ans =

         2
         5
         8

    >> g(:,1)

    ans =

         1
         4
         7

    >> g(1,:)

    ans =

         1     2     3

    >> g(2,:)

    ans =

         4     5     6

    >> p=1 2 3 4 5
     p=1 2 3 4 5
        |
    Error: Unexpected MATLAB expression.

    >> p=1 2 3 4 5
     p=1 2 3 4 5
        |
    Error: Unexpected MATLAB expression.

    >> p=[1 2 3 4 5]

    p =

         1     2     3     4     5

    >> p'=
     p'=
      |
    Error: The expression to the left of the equals sign is not a valid target for an
    assignment.

    >> p'

    ans =

         1
         2
         3
         4
         5

    >> g=[1 2 3;4 5 6;7 8 9]

    g =

         1     2     3
         4     5     6
         7     8     9

    >> g'

    ans =

         1     4     7
         2     5     8
         3     6     9

    >> eye(3)

    ans =

         1     0     0
         0     1     0
         0     0     1

    >> eye(1)

    ans =

         1

    >> eye(2)

    ans =

         1     0
         0     1

    >> eye(4)

    ans =

         1     0     0     0
         0     1     0     0
         0     0     1     0
         0     0     0     1

    >> eye(4,5)

    ans =

         1     0     0     0     0
         0     1     0     0     0
         0     0     1     0     0
         0     0     0     1     0

    >> eye(5,4)

    ans =

         1     0     0     0
         0     1     0     0
         0     0     1     0
         0     0     0     1
         0     0     0     0

    >> z=[1 2 4 5 6]

    z =

         1     2     4     5     6

    >> diag(x)

    ans =

         1     0     0     0     0     0     0     0     0     0
         0     3     0     0     0     0     0     0     0     0
         0     0     5     0     0     0     0     0     0     0
         0     0     0     7     0     0     0     0     0     0
         0     0     0     0     9     0     0     0     0     0
         0     0     0     0     0    11     0     0     0     0
         0     0     0     0     0     0    13     0     0     0
         0     0     0     0     0     0     0    15     0     0
         0     0     0     0     0     0     0     0    17     0
         0     0     0     0     0     0     0     0     0    19

    >> rand(1,5)

    ans =

        0.8147    0.9058    0.1270    0.9134    0.6324

    >> rand(1,6)

    ans =

        0.0975    0.2785    0.5469    0.9575    0.9649    0.1576

    >> randn(1,7)

    ans =

        3.0349    0.7254   -0.0631    0.7147   -0.2050   -0.1241    1.4897

    >> randi(1,7)

    ans =

         1     1     1     1     1     1     1
         1     1     1     1     1     1     1
         1     1     1     1     1     1     1
         1     1     1     1     1     1     1
         1     1     1     1     1     1     1
         1     1     1     1     1     1     1
         1     1     1     1     1     1     1

    >> randi(3,3)

    ans =

         1     3     1
         1     1     3
         1     3     2

    >> randi([1,20],3,3)

    ans =

         4    10    12
         6     8    11
        13    17    19

    >> h=randi([0,255],8,8)

    h =

        73   199   203   191   255   222    67   159
       193   239    79   115    20    21    37    89
       192    33   135    21   113   102    34   131
        97   145    42    58    27    66   222   102
       145   120   154   233   246   204   148    19
        19     3    67    39     1   110   140    61
        13    86   167   211   198   233    37    31
       135    41   176   137   209    46   218    47

    >> image(y)
    >>
    no image
    • Title : MATLAB basic commands for beginners
    • Posted by :
    • Date : 20:23:00
    • Labels :
    • Blogger Comments
    • Facebook Comments

    0 comments:

    Post a Comment

    Top