SOS Making a for loop for multiple combinations

1 Ansicht (letzte 30 Tage)
MadjeKoe
MadjeKoe am 15 Okt. 2020
Kommentiert: Walter Roberson am 16 Okt. 2020
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!

Antworten (1)

Walter Roberson
Walter Roberson am 15 Okt. 2020
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 Kommentare
MadjeKoe
MadjeKoe am 16 Okt. 2020
I cannot get it to work, can you please explain to me how it works?
Walter Roberson
Walter Roberson am 16 Okt. 2020
[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.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Startup and Shutdown finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by