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!
0 个评论
回答(1 个)
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 个评论
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 Center 和 File Exchange 中查找有关 Matrix Indexing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!