Finding the maximum two values within one field conditioned on the values in another field
1 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
Voss
2022-6-20
% 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]))
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Interactive Model Editing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!