do while in matlab

10 views (last 30 days)
asim asrar
asim asrar on 2 Nov 2019
Answered: KALYAN ACHARJYA on 2 Nov 2019
i have a condition for my code
stage A
A1= Zmed-Zmin
A2=Zmed-Zmax
if A1 >0 and A2 <0 go to stage B
else w=w+1
if w < wmax ,repeat stage A
else output zmed
stage B
B1= Zxy -Zmin
B2 = Zxy - Zmax
if B1>0 and B2<0 Output Zxy
else output Zmed
can someone help me in for this code
i tried writing it as
while 1
A1=Zmed-Zmin
A2=Zmed-Zmax
if A1>0 && A2<0 break
else w=w+1;
if w <= Wmax continue
else
B(i,j)=Zmed;
end
end
B1=Zxy-Zmin
B2=Zxy-Zmin
if B1>0 && B2<0
B(i,j)=Zxy;
else
B(i,j)=Zmed;
end
but its not working
  2 Comments
darova
darova on 2 Nov 2019
Try continue instead of break
asim asrar
asim asrar on 2 Nov 2019
but i have the condition that if A>0 and A2<0
then i have to come out of the loop
so i have to use brak for that ,
my question is how to code this conditions -
stage A
A1= Zmed-Zmin
A2=Zmed-Zmax
if A1 >0 and A2 <0 go to stage B
else w=w+1
if w < wmax ,repeat stage A
else output zmed
stage B
B1= Zxy -Zmin
B2 = Zxy - Zmax
if B1>0 and B2<0 Output Zxy
else output Zmed

Sign in to comment.

Accepted Answer

KALYAN ACHARJYA
KALYAN ACHARJYA on 2 Nov 2019
% Stage A
while 1
A1=Zmed-Zmin
A2=Zmed-Zmax
if A1>0 && A2<0
break;
else
w=w+1;
if w<=Wmax
continue;
else
B(i,j)=Zmed % Assumed that i & j are already defined
break; % Assumed that after this step pass to stage B, as not defined in the question
end
end
end
% Stage B
B1=Zxy-Zmin
B2=Zxy-Zmin
if B1>0 && B2<0
B(i,j)=Zxy;
else
B(i,j)=Zmed;
end
Please try, any issue let me know?

More Answers (0)

Categories

Find more on Programming in Help Center and File Exchange

Products


Release

R2015b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!