using ismember function column by column

7 visualizaciones (últimos 30 días)
Sharah
Sharah el 9 de En. de 2016
Comentada: dpb el 10 de En. de 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.

Respuesta aceptada

dpb
dpb el 9 de En. de 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 comentarios
Sharah
Sharah el 9 de En. de 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 el 10 de En. de 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...

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Workspace Variables and MAT-Files en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by