I have 3 columns of data:
time = [1;2;3;4;5;6;7;8;9;10;11;12;13;14;15;16];
category = [1;1;1;1;2;2;2;2;3; 3; 3; 3; 4; 4; 4; 4];
data = [1;1;0;1;2;2;1;2;3; 3; 2; 3; 4; 4; 4; 3];
I am using the following to extract the minimum data values for each category:
groupmin = accumarray(category,data,[],@min)
Which outputs:
groupmin = [0;1;2;3]
However, I would really like to have an output that also tells me which time point the minimums are from, e.g.
timeofgroupmin = [3;7;11;16]
groupmin = [0;1; 2; 3]
Alternatively, I would like to have the minimums output in a vector of their own, with NaNs for any row which was not the minimum of its group, e.g.
groupminallrows = [NaN;NaN;0;NaN;NaN;NaN;1;NaN;NaN;NaN;2;NaN;NaN;NaN;NaN;3];
Either approach would solve my problem. As a Matlab novice I'm struggling to know which terms to search for.