Clear Filters
Clear Filters

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

2 views (last 30 days)
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!

Accepted Answer

KSSV
KSSV on 27 Oct 2017
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 Comments
theintern
theintern on 27 Oct 2017
Also, can I use table for it? T= table(var1,var2,var3..) but each iteration it sould add new results.

Sign in to comment.

More Answers (0)

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!