Effacer les filtres
Effacer les filtres

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

2 vues (au cours des 30 derniers jours)
theintern
theintern le 27 Oct 2017
Commenté : theintern le 27 Oct 2017
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!

Réponse acceptée

KSSV
KSSV le 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 commentaires
theintern
theintern le 27 Oct 2017
Also, can I use table for it? T= table(var1,var2,var3..) but each iteration it sould add new results.
theintern
theintern le 27 Oct 2017
Hello, thank you so much, it works!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by