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

1 次查看(过去 30 天)
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!

回答(1 个)

Image Analyst
Image Analyst 2019-3-23
编辑:Image Analyst 2019-3-23
Try
[N2, indexes] = min(data(:, startT:endT), 1); % Get min of every column between column "startT" and column "endT"
  2 个评论
User48765
User48765 2019-3-23
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 2019-3-23
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)

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Matrix Indexing 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by