elseif using specific sets
Mostra commenti meno recenti
Hello, I need to evaluate a function for specific sets, ideally don't want to evalute the function for all sets so once it is above the condition to stop. I try to use the "elseif" statement but it never actually enters the elseif and terminates, even though it should enter.
Example
xa=[1 2] ; xb=[0 1] ; xc=[-1 4]; xd=[4 7]; xe=[10 10]; xf=[0 0];
y=xa(1)+xa(2)
if y<10
y=xb(1)+xb(2)
elseif y<10
y=xc(1)+xc(2)
elseif y<10
y=xd(1)+xd(2)
elseif y<10
y=xe(1)+xe(2)
else
y=xf(1)+xf(2)
end
Above, in the "xa" case, y=3 so it enters the if statament, evaluates the "xb" case and gets y=1 so it should enter the elseif of case "xc", but it terminates.
In this example, I need the final y to be the case xd so y=11. This is the first instance the criterion is not satisfied.
Do you know what I'm doing wrong and how to fix it? Thanks
Risposta accettata
Più risposte (0)
Categorie
Scopri di più su App Building in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!