How can I change this loop to a switch loop?
조회 수: 1 (최근 30일)
이전 댓글 표시
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
Alexandra Harkai
2016년 11월 21일
' 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?
답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Fourier Analysis and Filtering에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!