do while in matlab

10 visualizzazioni (ultimi 30 giorni)
asim asrar
asim asrar il 2 Nov 2019
Risposto: KALYAN ACHARJYA il 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 Commenti
darova
darova il 2 Nov 2019
Try continue instead of break
asim asrar
asim asrar il 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

Accedi per commentare.

Risposta accettata

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

Più risposte (0)

Categorie

Scopri di più su Programming in Help Center e File Exchange

Prodotti


Release

R2015b

Community Treasure Hunt

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

Start Hunting!

Translated by