필터 지우기
필터 지우기

I would like to save each value which fulfill the condition.

조회 수: 2 (최근 30일)
theintern
theintern 2017년 10월 27일
댓글: theintern 2017년 10월 27일
Hello community,
x=7;
while 7<=x<=10
for i=lenght(z)
for j=lenght(y)
Calculate equation A and eq. B, depend y and z
if t<0.5 && k<0.5
Put New values for eq. A and eq. B
break
end
end
end
x=x+1
end
For example, at 1st step x=7, I will calculate 2 values and when they fulfill the conditions, I would like to save the new values and go to x=8 step. Can I see the results at the end (when the all loops are finished) like : x=7 t=0.4, k=0.3 A=27 B=13 x=8... x=9... x=10...
I hope it is clear, if it is not, please inform me to explain more. Thanks in advance!

채택된 답변

KSSV
KSSV 2017년 10월 27일
This demo might be useful, for you:
count = 0 ; % initialize a count
iwant = zeros([],2) ; % initialize the required out put
while count ~= 10 % a while loop
x = rand ; y = rand ; % some values
if x < 0.5 && y < 0.5 % a condition to save the result x, y
count = count+1 ; % increment the count
iwant(count,:) = [x y] ; % store values
end
end
  댓글 수: 3
theintern
theintern 2017년 10월 27일
Also, can I use table for it? T= table(var1,var2,var3..) but each iteration it sould add new results.
theintern
theintern 2017년 10월 27일
Hello, thank you so much, it works!

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

추가 답변 (0개)

카테고리

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