How to order variables by their size?

3 vues (au cours des 30 derniers jours)
Richie
Richie le 22 Mar 2019
Commenté : Star Strider le 22 Mar 2019
Hi all,
Assuming I have these time-points, marking the start of a condition... I have 3 conditions (names = A, B and C), each with 5 consecutive blocks starting at (onsets)...
So onset times of these conditions are:
onsets{1,1} = [7848 8477 9099 9699 10315]
onsets{1,2} = [10923 11548 12136 12748 13353]
onsets{1,3} = [4565 5359 5985 6580 7211]
These correspond to:
names{1,1} = "A"
names{1,2} = "B"
names{1,3} = "C"
i.e. A_onsets = [7848 8477 9099 9699 10315]
As can be seen, when I sum these time-points (of onsets), the order of presentation was actually C, A, B.
sum_A = 45438 %sum_A = sum(onsets{1,1}))
sum_B = 60708 %sum_B = sum(onsets{1,2})
sum_C = 29700 %sum_C = sum(onsets{1,3})
How can I return an array of the order of the presentation of the conditions... e.g. order = ["C", "A", "B"]
Many many thanks in advance :)
R

Réponse acceptée

Star Strider
Star Strider le 22 Mar 2019
Try this:
[~,ix] = sort(cellfun(@sum, onsets));
Out = names(ix)
producing:
Out =
1×3 cell array
{["C"]} {["A"]} {["B"]}
  2 commentaires
Richie
Richie le 22 Mar 2019
This is beautiiful!
Thank you so much.
Star Strider
Star Strider le 22 Mar 2019
As always, my pleasure!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Resizing and Reshaping Matrices dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by