是否有一种方法可以case
在 MATLAB 中运行多个语句(例如 3 个中的 2 个)switch
?还是我必须使用一系列if
语句?我想做类似的事情:
test = {'test1','test2'}
switch test
case 'test1'
disp('test1')
case 'test2'
disp('test2')
case 'test3'
disp('test3')
end
输出:
test1
test2
附带说明:有没有办法并行化这些代码,以便可以同时运行不同的情况?
if
如果您 1/ 想要测试多个案例 2/parallelize,则该语句会更合适。
就像是
if ismember('test1',test)
%code
end
如果要使其并行,可以通过以下方式进行:
test
是您的数据,case
是包含所有可能性的单元格
parfor(i=1:length(cases)){ %you need to parse the cases not the data
if(ismember(case{i},test)){
%code
}
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句