Finding the maximum two values within one field conditioned on the values in another field
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hi,
I have a structure with 8 rows and 11 fields. The data contained in the 8 rows (corresponding to summary data of 8 blocks) belongs to different conditions of an experiment (rows 1,2,5,6 belong to condition A and rows 3,4,7,8 belong to condition B). I would like to extract the index (from 1 to 8) of the two maximum values within each condition.
I am currently struggeling with writing a code that extracts the maximum values only from the rows of the relevant condition and at the same time returns the number of the block/row that it refers to.
So I would, for example, like to get the maximum values of condition B, which are in my case in row/block 4 and 7. How do I do this?
Would be so grateful for an answer!!!
2 commentaires
Réponse acceptée
Voss
le 20 Juin 2022
% random data
feedback = struct('gains',num2cell(rand(1,8)));
disp([feedback.gains]);
%separately save gains from Condition A and Condition B
idxA = [1 2 5 6];
idxB = [3 4 7 8];
gains_total = [feedback.gains];
condA_data = gains_total(idxA);
condB_data = gains_total(idxB);
%sort gains from free and forced choice blocks in descending order
[sorted_condA,sorted_idxA] = sort(condA_data,'descend');
[sorted_condB,sorted_idxB] = sort(condB_data,'descend');
%find the index of the two best free and forced choice blocks
top2_condA_blocks = idxA(sorted_idxA([1 2]))
top2_condB_blocks = idxB(sorted_idxB([1 2]))
2 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Structures 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!