-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclass20180122_IT2N2_ControlStructures.m
118 lines (105 loc) · 2.46 KB
/
class20180122_IT2N2_ControlStructures.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
function [] = class20180122_IT2N2_ControlStructures (pick)
pick=5;
if(pick==1)
%
DisplayMessage(pick);
disp(['Lets do some repeating with "for".']);
for(n=0:12)
m(2*n+1)=2*n;
end%for
m
elseif(pick==2)
%
DisplayMessage(pick);
disp(['Lets do some repeating with "while".']);
n=0;
while(n<5)
%
m(n+1)=n;
n=n+1;
end%while
m
elseif(pick==3)
%
DisplayMessage(pick);
disp(['Lets do some 3D plotting.']);
Nx=300;
x=linspace(0,15,Nx);
Ny=60;
y=linspace(0,1,Ny);
X=repmat(x',1,Ny);
Y=repmat(y,Nx,1);
Z=sin(X).*Y.^2;
F=figure(1);
clf;
%get(F);
S=surf(Z);
%get(S);
set(S,'EdgeColor','none');%[0 0 0]
az=0;%-37.5;
el=0;%30;
view(az,el);
elseif(pick==4)
%
DisplayMessage(pick);
disp(['Lets do some 3D plotting animated by view.']);
Nx=100;
x=linspace(0,15,Nx);
Ny=150;
y=linspace(0,20,Ny);
X=repmat(x',1,Ny);
Y=repmat(y,Nx,1);
Z1=1*sin(X).*Y.^2;
Z2=1*cos(Y).*X.^2;
zmin=min( min(min(Z1)),min(min(Z2)) );
zmax=max( max(max(Z1)),max(max(Z2)) );
F=figure(1);
N=100;
for(n=0:N)
t=n/N;
S=surf((1-t)*Z1+t*Z2);
set(S,'EdgeColor','none');%[0 0 0]
az=-37.5;
el=30;
view(az+n,el);
zlim([zmin,zmax]);
pause(0.05);
end
elseif(pick==5)
%
DisplayMessage(pick);
disp(['Lets do some 3D plotting animated by view.']);
Nx=100;
x=linspace(0,15,Nx);
Ny=150;
y=linspace(0,20,Ny);
X=repmat(x',1,Ny);
Y=repmat(y,Nx,1);
Z1=1*sin(X).*Y.^2;
Z2=1*cos(Y).*X.^2;
zmin=min( min(min(Z1)),min(min(Z2)) );
zmax=max( max(max(Z1)),max(max(Z2)) );
F=figure(1);
N=1000;
for(n=0:N)
t=n/N;
W=10;
S=surf(cos(W*2*pi*t)*Z1+sin(W*2*pi*t)*Z2);
set(S,'EdgeColor','none');%[0 0 0]
az=-37.5;
el=30;
w=25;
view(az+n,el*(1+sin(w*2*pi*t)));
zlim([zmin,zmax]);
axis off;
title(['0<',num2str(t),'<1']);
pause(0.05);
end
else
%
disp(['Your choice for the input was illegal. Please choose again.']);
end
end%class20180122_IT2N2_ControlStructures
function [] = DisplayMessage (input)
disp(['You chose input ',num2str(input),'.']);
end%DisplayMessage