Beruflich Dokumente
Kultur Dokumente
8. IF-ELSE
--> a
--> 6-4 a =
ans =
10.
2.
--> b
--> 2*3+5 b =
ans =
10.2
11.
if a > b then
--> 2/0.5 > disp(a)
ans = > else
> disp(b)
4. > end
5. LOGICAL OPERATIONS
--> a = 1
--> b = 10.2 a =
b =
1.
10.2
--> b = 2
BOOLEAN VARIABLES b =
--> c = true //wrong
2.
Undefined variable: true
--> a&b
--> c = %t ans =
c =
T
T
--> a && b
--> f = %f ans =
f =
T --> bitxor(1,2)
ans =
--> a!=b//‘a!’ is treated as a var
a! = 3.
F --> n =
--> ~2 5.
ans = FUNCTION TO CHECK FOR EVEN
--> function y = isEven(n)
F > if modulus(n,2)==0 then
> disp("Even")
--> ~1 > else
ans = > disp("Odd")
> endfunction
F >
--> ~0 --> n
ans = n =
T 5.
"Even" 2.
--> c
QUESTIONS 11-20 c =
--> a
a =
1.
--> global a
--> a
a =
2.
STRING CONCATENATION
--> "Line1" + "Line2"
ans =
--> a = int(a)
a =
2.
--> a = bool2s(a)
a =
1.
GRAPH PLOTTING - SUBPLOT
-> function [] = makePlot()
> subplot(221)
> plot(sin(x),x)
> subplot(222)