Académique Documents
Professionnel Documents
Culture Documents
2. Command Window
The command window is user to enter variables and to run functions and M-file scripts.
We can enter the matlab functions at the command window prompt. This command window also
displays the result.
4. Help Browser
Use the Help browser Contents for a product to view Functions .in help browser there is
alphabetical list or Functions and also by category, to view more extensive help for a function in
the Help browser run doc functionname.
6. Workspace Browser
In work space window all the variables that we use in command window are shown with
their name, value and class.
Section E: Functions
Task 8: Use built in functions
Rand is a built in function which takes one or more inputs e.g:
rand(3,4)
It should output a 3×4 matrix of random numbers.
0.8
The plot function allows for many customisations 0.6
such as line colours, line styles, etc. 0.4
x1 = 0:pi/100:2*pi; 0.2
x2 = 0:pi/10:2*pi; 0
plot(x1,sin(x1),‟r:‟,x2,sin(x2),‟b+‟); -0.2
-0.4
-0.6
-0.8
-1
0 1 2 3 4 5 6 7
TASK 17 Imaginary and complex data 1
0.8
0.6
When plot is used on complex data the imaginary part is 0.4
t = 0:pi/10:2*pi; -0.4
plot(exp(j*t),’-o’); -0.6
-0.8
-1
-1 -0.8 -0.6 -0.4 -0.2 0 0.2 0.4 0.6 0.8 1
3
[x,y,z] = peaks;
pcolor(x,y,z) 0
shading interp
hold on -1
contour(x, y, z, 20,'k')
hold off -2
-3
x1 = 0:pi/100:2*pi
x2 = 0:pi/10:2*pi
figure(1)
plot(x1,sin(x1),‟r:‟);
figure(2)
plot(x2, sin(x2),‟b+‟);
Using above code the two figures are shown in two different windows
[X,Y,Z] = cylinder(4*cos(t)); 0 0
subplot(2,2,1);
mesh(X); -5
40
-5
40
40 40
subplot(2,2,2); 20
0 0
20 20
0 0
20
mesh(Y);
subplot(2,2,3);
mesh(Z); 1 1
mesh(X,Y,Z); 0 0
grid lines can be set using: 40
20
40
5
0
5
grid on 0 0
20
-5 -5
0
grid off
The command subplot is used to have more than one figures in one or same window. The
command mesh is used to show the figure in three dimension.
Section G: Flow Control
Task 21: Use of input command
Input command is used to take the input from user. E.g.
z = input(‟enter a value for z‟)
Task 22: Use of if command
If command is used to select different alternatives based on different conditions for example:
temperature = input(‟enter a temperature ‟)
if temperature >= 90
disp(‟It’s getting hot‟);
elseif temperature < 90 & temperature > 50
disp(‟This is just right‟);
else
disp(‟I think I will get my coat‟);
end
Output:
enter a temperature 101
It’s getting hot
Task 23: Use of switch command
Switch statement is used instead of if statement and have same functionality as if
statement has.