elseif using specific sets

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

 采纳的回答

I'll use "while" instead, thanks though
X=[1 2; 0 1; -1 4; 4 7; 10 10; 0 0]
ii=1
y=1e-10
while y<10
y=X(ii,1)+X(ii,2)
ii=ii+1
end

更多回答(0 个)

类别

帮助中心File Exchange 中查找有关 App Building 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by