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 CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by