Info
この質問は閉じられています。 編集または回答するには再度開いてください。
Continue in a for loop if a string in a string array isn't present
2 ビュー (過去 30 日間)
古いコメントを表示
Hi,
I currently have this code:
def = {'Acc_X','Acc_Y','Acc_Z','Gyr_X','Gyr_Y','Gyr_Z'};
RF = {'RF1','RF2','RF3','RF4'};
for k = 1:NSensors
figure();
suptitle('REACH FORWARD');
for q = 1: length(def)
for o = 1: length(RF)
subplot(2,3,q);
plot(H9.MEAN_SUBJECT.(RF{o})(k).(def{q}));
hold on;
plot(H17.MEAN_SUBJECT.(RF{o})(k).(def{q}),':');
hold on;
xlim([0 100]);
xlabel('Time (%)');
ylabel(sprintf('%s',(def{q})));
end
end
end
However, for H9, RF3 does not exist, so I am trying (and obviously failing) to make the for loop skip this string if it is not present. Here is my attempt:
RF = {'RF1','RF2','RF3','RF4'};
for k = 1:NSensors
figure();
suptitle('REACH FORWARD');
for q = 1: length(def)
for o = 1: length(RF)
tf = ismember(RF,(RF{o}));
if tf(o) == 1
continue
end
subplot(2,3,q);
plot(H9.MEAN_SUBJECT.(RF{o})(k).(def{q}));
hold on;
plot(H17.MEAN_SUBJECT.(RF{o})(k).(def{q}),':');
hold on;
xlim([0 100]);
xlabel('Time (%)');
ylabel(sprintf('%s',(def{q})));
end
end
end
This gives me empty figures and thus no output.
I am aware that the "ismember" command might not the best in this situation, but I cannot seem to find a valid alternative as "isNaN" is not applicable and "exist" does not wrok for strings.
Any help would be greatly appreciated.
Thanks in advance!
2 件のコメント
Adam
2019 年 4 月 30 日
tf = ismember(RF,(RF{o}));
will surely never return false. You are testing if an element of an array is in that same array, which it will always be.
Judging from your comments and what you attempt to do in the code I assume you want a test that includes something more like
if isfield( H9, RF{o} )
...
end
回答 (0 件)
この質問は閉じられています。
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!