MATLAB: Extract datapoint corresponding to index from maximum of an array

maximumminimumsecond output

I need to extract the force corresponding to the maximum strain for every cycle count from the attached file.
data=xlsread('Sample Data.xlsx');
count=data(:,1);
strain=data(:,2);
force=data(:,3);
unique_counts=unique(count);
maxforce=zeros(size(unique_counts));
maxstrain=zeros(size(unique_counts));
for n=1:numel(unique_counts)
c=unique_counts(n);
rows=ismember(count,c);
strain_=strain(rows);
force_=force(rows);
maxstrain(n)=max(strain_);
%% Here is where I need input
maxforce(n)= ?
end
Thank you

Best Answer

The max() and min() functions can also return the index where the maximal/minimal value occurs. If I'm interpreting your code correctly, it would be something like this:
for n=1:numel(unique_counts)
c=unique_counts(n);
rows=ismember(count,c);
strain_=strain(rows);
force_=force(rows);
% get the index where the maximum occurred
[maxstrain(n) idx]=max(strain_);
maxforce(n)=force_(idx);
end
Related Question