SOS Making a for loop for multiple combinations
2 次查看(过去 30 天)
显示 更早的评论
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!
0 个评论
回答(1 个)
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 个评论
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 Exchange 中查找有关 Loops and Conditional Statements 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!