While loop for a stopping criterion and check if it positive
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Hello everyone,
Sorry if the title is not clear enough, it is quite hard to put in to simple word. In the current Matlab code I am working on, I have a while loop of the type:
while and(X > eps1, Y > eps2) && count < it_max
%calculations
end
with X, Y the variables of interest; eps1, eps2 the stopping criterias. My problem is that eps1 and eps2 are positive, and X and Y can take negative values. However these must be positive and I would like to add a condition to make the while loop continue when X and Y are negative (without any absolute value function).
Thank you.
0 Kommentare
Antworten (1)
Image Analyst
am 2 Sep. 2019
I don't know why you don't want to use the abs() function but you can do it without it like this:
while ((X > eps1 && Y > eps2) || (X < eps1 && Y < eps2)) && count < it_max
%calculations
count = count + 1;
end
Siehe auch
Kategorien
Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!