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

2 次查看(过去 30 天)
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.

请先登录,再进行评论。

更多回答(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