Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
如果达到条件并结束程序代码的仿真,是否可以停止或中断 MATLAB 中的代码?例如,我有一个涉及计算参数的循环,并且该值变成一个复杂的否。我希望我的代码停止执行并返回参数值变得复杂的计数器的值。
对的,这是可能的。如果你想退出你的脚本,你可以使用这个:
if complex(parameter) disp(counter); return; end
如果你想退出一个函数并将计数器的值返回给调用者,你可以使用这个:
if complex(parameter) return(counter) end
如果您只想跳出循环,请使用以下命令:
for ... if complex(parameter) break; end end print(counter)