Extracting max or min values from each row in a matrix, and storing them and their indices.
조회 수: 2 (최근 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!