using ismember function column by column

9 views (last 30 days)
Sharah
Sharah on 9 Jan 2016
Commented: dpb on 10 Jan 2016
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.

Accepted Answer

dpb
dpb on 9 Jan 2016
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 Comments
Sharah
Sharah on 9 Jan 2016
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 on 10 Jan 2016
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...

Sign in to comment.

More Answers (0)

Categories

Find more on Matrices and Arrays in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!