SOS Making a for loop for multiple combinations

2 ビュー (過去 30 日間)
MadjeKoe
MadjeKoe 2020 年 10 月 15 日
コメント済み: Walter Roberson 2020 年 10 月 16 日
I have a question. I'm doing an experiment where you have to guess the orientation of 1 of the 4 stimuli you've just seen. Here, I am comparing the orientation of the 3rd stimulus to the orientation of 2nd stimulus, where the target was the 2nd stimulus. Is there a possibility to make a loop for this and put all the combinations in a matrix? With everytime a different target? So when stimulus 1 is the target, for all other stimuli the relative orientation is calculated etc.
rel32 = ori2(targets==2) - ori3(targets==2);
Can somebody please help me with this?? Thank u in advance!

回答 (1 件)

Walter Roberson
Walter Roberson 2020 年 10 月 15 日
G = findgroups(target);
rel32 = splitapply(@minus, ori2, ori3) %if there is exactly one match per target
rel32 = splitapply(@(o2, o3) {o2-o3}, ori2, ori3) %if there are multiple matches per target
  2 件のコメント
MadjeKoe
MadjeKoe 2020 年 10 月 16 日
I cannot get it to work, can you please explain to me how it works?
Walter Roberson
Walter Roberson 2020 年 10 月 16 日
[G, targ] = findgroups(targets);
rel32 = splitapply(@minus, ori2, ori3, G) %if there is exactly one match per target
rel32 = splitapply(@(o2, o3) {o2-o3}, ori2, ori3, G) %if there are multiple matches per target
In the "multiple matches per target" case, the output will be a cell array with one entry for each different target. The order is probably increasing numeric target order, but that is not guaranteed; instead you should look at targ to see which value of targets corresponds to each group.
So for example rel32{1} would correspond to ori2(G==1)-ori3(G==1) and in turn that is probably the same as ori2(targets==1)-ori3(targets==1) but check targ(1) to see for sure what value of targets was being tested. In particular, if there just happens to be a gap in target values, such as if targets==2 never occurs, then the group numbers G will not correspond to target number.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by