do while in matlab

10 vues (au cours des 30 derniers jours)
asim asrar
asim asrar le 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 commentaires
darova
darova le 2 Nov 2019
Try continue instead of break
asim asrar
asim asrar le 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

Connectez-vous pour commenter.

Réponse acceptée

KALYAN ACHARJYA
KALYAN ACHARJYA le 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?

Plus de réponses (0)

Catégories

En savoir plus sur Programming dans Help Center et File Exchange

Produits


Version

R2015b

Community Treasure Hunt

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

Start Hunting!

Translated by