elseif using specific sets
1 次查看(过去 30 天)
显示 更早的评论
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
0 个评论
采纳的回答
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Whos 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!