Extracting max or min values from each row in a matrix, and storing them and their indices.
1 view (last 30 days)
Show older comments
Hi! I am trying to extract the max and min values between columns startIdx:endIdx
function N2 = extractN2(data, startT, endT)
Fs = 250; % Sampling Frequency (Hz)
Ts = 1/Fs; % Sampling Interval (s)
startIdx = floor(startT / (Ts * 1E+3))+51; % Start Time (ms)
endIdx = floor(endT / (Ts * 1E+3))+50; % End time (ms)
sTimes = [-200:4:796];
for l=1:size(data)
???
end
of each row of a matrix, as well as the indices of these values.
So for example, I have a matrix (64x250) and I want to extract the min value between columns 70:124, and store this value in a new variable. I also want to get the index of this value. I was thinking of doing it in a loop, so that it runs through each row of the matrix, and the outputswould be 64x1 (one for min values and one for indices). Any help or tips would be appreciated!
0 Comments
Answers (1)
Image Analyst
on 23 Mar 2019
Edited: Image Analyst
on 23 Mar 2019
Try
[N2, indexes] = min(data(:, startT:endT), 1); % Get min of every column between column "startT" and column "endT"
2 Comments
Image Analyst
on 23 Mar 2019
I forgot the middle brackets. Presumably you looked it up in the help, but here is the solution:
[N2, indexes] = min(ERP_CG1(:, 88:124), [], 1)
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!