


Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!



(e.g. variable values, data, signals…)
(Tools include math functions, decision structures, while loops, for loops…)
(e.g. variable values, plots, control signals …)
While Loops
disp('Start of problem') a = 4 while a > 1 b = 2; while b <= a b = b + 1; disp(ab) end a = a - 1 end disp('End of problem')*
Nested while loop
Loop counters
(Notice how all loop counters must be initialized before the loop)
If - Elseif – Else Branching
a = [5 8 -4 -3 7 1 9]; N=0; while (N <= 5) N=N+ if ( N==1 | N > 6) Output = a(N) ; disp(Output) elseif ( (N == 3) | (N >= 5) ) Output = a(N+1); disp(Output) else Output = a(5); disp(Output) end end
Switch – Case
Branching
v=[1 2 3 4 5 6 7]; k=5; while k > 0 switch (k+1) case {1,5} new=v(k)+v(k+1) case {4,6} new=v(k) case 2 new=- otherwise new=v(k+2) end k = k - 1; end
Array indexing
Loop counter
Array Indexing
Subplots
(^00 2 4 6 )
2
4
6
8 Linear Plot
x
y
0 2 4 6 8
10 0.
10 0.
Semi-Log Plot
LN(y)
x 10
0
10 0.
10 0.
Log-Log Plot
LN(y)
LN(x)
SUBPLOT(2,1,1), PLOT(x,y) SUBPLOT(2,1,2), PLOT(x,z)
plots x vs. y on the top half of the window and x vs. z on the bottom half.
Subplot command
Subplot
output