using ismember function column by column

6 次查看(过去 30 天)
let say i have this code:
VoidSubject = [1, 3, 6];
VoidTrial = [2, 3, 5];
for subject = 1:20
for trial = 1:10
if ismember(subject, VoidSubject) && ismember(trial, VoidTrial)
continue
end
%some importing data into struct code here
end
end
using my current code, when ever the subject is a member of VoidSubject, the code will skip all the data from Void Trial. Which means, for subject 1, 3 6, all trials of 2, 3 and 5 will be skipped.
What I want to do is, i want to make is so that they will remove trail 2 from subject 1, trial 3 from subject 3 and trial 5 from subject 6. I know there should be a way but I have a mind block right now so I would appreciate if somebody could help me. Hope my question make sense.

采纳的回答

dpb
dpb 2016-1-9
Presuming the lists are sorted and to be used concurrently as described, keep an auxiliary counter to "walk" through them...
idx=1; % first condition index initialization
for subject = 1:20
for trial = 1:10
if ismember(subject, VoidSubject(j)) && ismember(trial, VoidTrial(j))
j=j+1; % increment for next pair
continue
end
%some importing data into struct code here
end
end
  2 个评论
Sharah
Sharah 2016-1-9
your solution does not work. which makes sense because then the idx will go to above the size of the VoidSubject.
Also, it does not work if I have the same VoidSubject with multiple value of VoidTrial. For example
VoidSubject = [1,1,3] VoidTrial = [2,4,1]
Looking forward to another suggestion
dpb
dpb 2016-1-10
It's not really clear what you're after here...what's the end result intended to be? That is, why are you iterating over both subject and trial instead of not selecting what's wanted and then iterating over that subset.
Clearly the previous swipe at it was intended to be used only for the length of the subset arrays...

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Workspace Variables and MAT-Files 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by