我正在使用 MATLAB 的 m 文件编辑器,我需要从一行跳到另一行。如果我需要从For
...内部跳转end
,我不能使用通常的“while”技术。
反正有没有从一条线跳到另一条线,就像goto
在 C 中一样?
Arash
问问题
89678 次
4 回答
9
matlab中没有goto。但是,这并不是说您不能构建代码以对代码使用 {if, else, elseif, end} 结构形式。或者使用 {switch, case, end} 形式。或者调用一个函数(或子函数或嵌套函数)来解决你的问题。或者使用 continue/break 来构建你的代码。人们总是可以使用一种现有的可用流量控制形式来解决这些问题。
函数的使用可以通过其他方式改进您的代码,通常是通过使其更加模块化,从而更容易调试和编写。
于 2009-07-05T11:09:20.670 回答
0
轻松解决问题:
caseno = input('input your case no');
switch (caseno)
case 1
disp('this first section will run');
case 2
disp('this second section will run');
otherwise
disp('wrong case no');
end
于 2019-01-18T23:59:14.037 回答
-1
for j = 1: 1: 24
% LABEL start
a = a + j;
if a > 10
goto('start') % If condition satisfied goto label start
return
else
a = a + 1;
end
end
于 2017-01-24T08:50:46.507 回答