using ismember function column by column
7 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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.
0 Commenti
Risposta accettata
dpb
il 9 Gen 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 Commenti
dpb
il 10 Gen 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...
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Workspace Variables and MAT-Files in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!