gpt4 book ai didi

matlab - 如果发生错误,如何跳过 `for`循环索引

转载 作者:行者123 更新时间:2023-12-03 09:03:24 26 4
gpt4 key购买 nike

在Matlab中,如果发生错误,如何跳过特定的for循环索引和continue到下一个索引?请注意,我不知道哪个for循环索引将导致发生错误。

错误: Too many outputs requested. Most likely cause is missing [] around left hand side that has a comma separated list expansion

假设k = 5发生错误。
如何使for循环将索引k = 5continue跳过到k = 6

for k = 1:10
do stuff
if error occurs
skip k that causes error
go to next k
end
end

最佳答案

为此,您可以使用 try !

for k = 1:10
%do stuff
try
% portion of the code where error can occur
end
end

关于matlab - 如果发生错误,如何跳过 `for`循环索引,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39025442/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com