using ismember function column by column

6 ビュー (過去 30 日間)
Sharah
Sharah 2016 年 1 月 9 日
コメント済み: dpb 2016 年 1 月 10 日
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 Center および File ExchangeMatrices and Arrays についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by