MATLAB: How to find the index of splitapply

splitapply

I have this code where I split the data into intervals and I look to find the maximum value for each interval as below. I need to find the indexes of the maximum values (Result) as well to collect more information from the original matrix (data). For simplify I created the following example.
x = round(Data(:,18),0);
y = Data(:,17);
[uv,~,idx] = unique(x);
[Result] = splitapply(@max, y, idx);
How can I find the indexes correspond to the Result to get more information from the original data.
Thank you so much for your help.

Best Answer

The indices within each group or the indices over all of y? If the former,
indices = splitapply(@maxIndex, y, idx);
function out=maxIndex(z)
[~,out]=max(z);
end