是否可以像使用向量一樣在數值上遍歷MATLAB結構而不是使用字段名稱?以數字方式迭代MATLAB結構
簡單地說,我試圖做一個EML塊的Simulink中執行以下操作:
S.a.type = 1;
S.a.val = 100;
S.a.somevar = 123;
S.b.type = 2;
S.b.val = 200;
S.b.somevar2 = 234;
S.c.type = 3;
S.c.val = 300;
S.c.somevar3 = 345;
for i = 1:length(s)
itemType = S(i).type;
switch itemType
case 1
val = S(i).val * S(i).somevar1;
case 2
val = S(i).val * S(i).somevar2;
case 3
val = S(i).val * S(i).somevar3;
otherwise
val = 0
end
end
disp(var);
看到這個問題[如何訪問循環內的MATLAB結構域?](http://stackoverflow.com/questions/1882035/how-do-i-access-matlab-structure-fields-within-a-循環) – Aabaz