필터 지우기
필터 지우기

Extract value from Looping until or when condition is true

조회 수: 2 (최근 30일)
Ali Tawfik
Ali Tawfik 2019년 8월 25일
댓글: Ali Tawfik 2019년 8월 25일
Hi All,
I am trying to doing a loop with different values until condition met, I just do not wanna all the iteration to work, I wanna the iteration stops when or until condition is met, Also, I'd like to get out the values that met condition
So please help me
I fix the value of x and then obtain y ,
Again, I wanna the iteration stops when or until the condition is met
The following code works only to stop iteration but with no specifying which numbers from e could fit;
clear all;
yin2=[solve(-1>x+y,y), solve(x+y>20,y)];
e=(1:10);
for i=1:10
[a(i,:)]=matfunction(e(i));
z(i,:)=a(i,1);
s(i,:)=a(i,2);
if (-1<z(i,:)) && (s(i,:)>3);
break
display('ok')
z
else
display('bye bye')
end
end

답변 (1개)

KALYAN ACHARJYA
KALYAN ACHARJYA 2019년 8월 25일
Is this?
i=1;
while ~(-1<z(i,:) && s(i,:)>3)
[a(i,:)]=matfunction(e(i));
z(i,:)=a(i,1);
s(i,:)=a(i,2);
i=i+1;
end
Please note this is partial code, add initial lines of the code.
The while loop is run until this condition "-1<z(i,:) && s(i,:)>3" is false, when it true, loop will terminate.
  댓글 수: 1
Ali Tawfik
Ali Tawfik 2019년 8월 25일
Hi Kalyan,
Thanks for your answer.
I got the following error, when I try to run with your feedback:
Reference to a cleared variable z.
Also, I think you misunderstand me, because, I wanna add while inside the for loop ?.
I mean, I wanna run the loop, until the condition is met then terminate, and then know which variables could met that condition
Hope you could help.
Thanks,

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by