Extracting max or min values from each row in a matrix, and storing them and their indices.

2 views (last 30 days)
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!

Answers (1)

Image Analyst
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
User48765
User48765 on 23 Mar 2019
Hmm, when I do that, I get the following error;
Error using min
MIN with two matrices to compare and two
output arguments is not supported.
>> [N2, indexes] = min(ERP_CG1(:, 88:124), 1);
Image Analyst
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)

Sign in to comment.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!