How can I change this loop to a switch loop?
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
width=input('Enter a positive number: ');
disp(' ');
while width<0
width=input('Enter a positive number: ');
disp(' ');
end
%dimension input
dimension=input('Input an integer greater than 1: ');
disp(' ');
while (dimension<=1)
dimension=input('Input an integer greater than 1: ');
end
reorint=0;
while reorint==0
if isreal(dimension)&&mod(dimension,1)==0
reorint=1;
else
dimension=input('Input an integer greater than 1: ');
reorint=0;
end
end
%colors input
color1=input('Enter 1st color: red(r), yellow(y), green(g), black(k), blue(b), magenta(m), white(w), cyan(c): ','s');
disp(' ');
color2=input('Enter different 2nd color: red(r), yellow(y), green(g), black(k), blue(b), magenta(m), white(w), cyan(c): ','s');
disp(' ');
N=4;
R=width;
Phase=pi/4;
theta=zeros(1,N);
for b=1:N
theta(b)=2*pi*(b-1)*(1/4);
end
x1=R*cos(theta+Phase)/sqrt(2); %cosine function
y1=R*sin(theta+Phase)/sqrt(2); %sine function
for m= 0 : dimension-1
for n= 0 : dimension-1
if mod(m+n,2) == 0 %adding your columns and rows to fill them with 2 different colors
fill(x1+m*width, y1+n*width,color1);
else
fill(x1+m*width, y1+n*width,color2);
end
hold on;
end
hold on;
end
How can I change the for loops starting from where it say "for b=1:N;" and the rest of the code and make it into a switch loop? Even if I can't change all of it can a change a few parts of it?
2 Kommentare
Alexandra Harkai
am 21 Nov. 2016
' switch ' and loop statements are different and not directly interchangeable the way you sound to want them.
Why do you want to change those loops to a switch statement?
Antworten (0)
Siehe auch
Kategorien
Mehr zu Fourier Analysis and Filtering finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!