You are on page 1of 3

Matlab instructions:

Help function_name

Help . help space point //operations


Clc : clear the command window

Clear : clear all variables

Clear A : clear the variable A

Who : list all variables used

Whos : list all variables used with details

B=3 : normal number

B = [1 2 3] : vector

B = [1 2 3; 4 5 6] : Matrix ( “;” separate the rows)

For ex: to access the value 5 we write B(2,2)

- If we have:

D=
1 2
3 4
5 6

And we write:

D (4, : ) = [7 8]
D=
1 2
3 4
5 6
7 8

By this ex we have add the line (7 8) to the matrix

- If we want to select the 1st column only :


D ( : , 1)

Ans =

1
3
5
7

- If we want to access the 1st row :


D (1 , : )

Ans =

1 2
- If we want to let N take the values from 1 to 100

N = 1:100;

- If we want N to take {0, 0.4, 0.8, 1.2, 1.6, 2}

N = 0:0.4:2;

- To print a string to the screen, we use sprintf or disp or both:

Sprint (‘The value of pi is %5.3f, pi’, pi)

disp (sprintf(The value of pi is %5.3f,pi))

- If and (m>0, n>0)  if(m>0 &&n>0) in C


- … is used to mark a continuity of the command on the second line.
- The size command returns the number of rows and number of columns
for a given matrix.
- A.’  transpose (A) both command can be used.
- A+B A-B A*B M/N  M*inv(N)
- The command sum (A+B) add matrix A to matrix B, then add the sum
of the elements of the result matrix.  sum(A) +sum(B) .
- A.*B % ans = [A(1)*B(1) A(2)*B(2) A(3)*B(3) A(4)*B(4)]

If your PC has a speaker you could try


_load handel <Enter>
_sound(y,Fs) <Enter>
For a snatch of Handel’s Hallelujah Chorus.
For some different sounds you can try loading chirp, gong, laughter,
splat and train. You have to run sound(y,Fs) for each one.
a script file is a file that, if we enter its name at the command-line
prompt, MATLAB carries out each statement in the script file as if it
were entered at the prompt.

A script file may be listed in the Command Window with the


command type, e.g. type script_name.
When you run a script, you have to make sure that MATLAB’s
current directory (indicated in the Current Directory field on the right
of the desktop toolbar) is set to the directory in which the script is
saved.

You can change the current directory from the command line with cd
command, e.g. cd \mystuff
The command cd by itself returns the name of the current directory.

Suite p.78 (plot not a sinus)

You might also like