【发布时间】:2014-08-12 13:07:47
【问题描述】:
似乎在octave(也许还有matlab)中没有办法打破switch 声明,但我不确定......
P=rand(2,20);
mu=mean(P,2);
dim=2;
plot_mean=false;
for i=1:1
switch (dim)
case 2
% Print points as dots
plot(P(1,:),P(2,:),'.');
if (!plot_mean)
break;
endif
hold on
% Print mean values as red circles
plot(mu(1,:),mu(2,:),'or');
% Quite some more code following here with again several if statements that need to be broken out
case 3
% Similar for 3D case
% ...
endswitch
endfor
我刚刚把这个问题变成了一个完整的octave 程序,随时用其他函数调用替换plot 功能。重要的是我在1:1 周围添加了一个for 循环并使用break,但这当然只是一个技巧!
在octave中突破switch的正常方法是什么?
【问题讨论】:
标签: matlab switch-statement octave break