SOS Making a for loop for multiple combinations
2 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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 Commenti
Risposte (1)
Walter Roberson
il 15 Ott 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 Commenti
Walter Roberson
il 16 Ott 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.
Vedere anche
Categorie
Scopri di più su Loops and Conditional Statements in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!