Extract datapoint corresponding to index from maximum of an array
20 views (last 30 days)
Show older comments
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
0 Comments
Accepted Answer
DGM
on 23 Mar 2021
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
More Answers (0)
See Also
Categories
Find more on Matrix Indexing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!