How do I find the maximum/last index value from a list of indices

조회 수: 3 (최근 30일)
Alex
Alex 2016년 12월 24일
답변: Alex 2017년 3월 18일
I have imported some data to form an array called 'newData1.data' and then find the row/col indices for each value 1-49 in a vector called 'numbers'
numbers=1:1:49;
for i=1:length(numbers)
[row,col] = find(newData1.data' == i);
end
How do I find the greatest/maximum/last column number?
test(i) = max(col)
does not work within the loop. There are plenty of questions and answers on how to get the indices of the maximum value in the array, but that is not what I am looking for.
Best regards,
Alex

채택된 답변

Image Analyst
Image Analyst 2016년 12월 24일
Try this:
numbers = 1 : 1 : 49;
for k = 1 : length(numbers)
[rows, columns] = find(newData1.data' == numbers(k));
maxColumns(k) = max(columns)
end
  댓글 수: 2
Alex
Alex 2016년 12월 24일
This is the same thing I was doing. It returns the error, "Index exceeds matrix dimensions."
Image Analyst
Image Analyst 2016년 12월 24일
It's not exactly the same thing you were doing since my code is more robust in that it compares "numbers" instead of i. Your code defines numbers but then never uses it. Anyway there is nothing wrong so the only way we can continue is if you attach your data via a .mat file.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Alex
Alex 2017년 3월 18일
Solution: I found that I created a variable called min/max: max=max(data) min=min(data) By changing these lines to: dmax=max(data) dmin=min(data) the max(idx), min(idx) function as expected.

카테고리

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