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!