Finding the row and column number in a matrix
이전 댓글 표시
for a matrix [1 2 3 4 6 10 7 5 9] mXn matrix-- how is it that i can find the min or max element and then find the row number and the column number for further use in calculations
댓글 수: 1
Meryem
2014년 9월 4일
You can have an answer with a few lines of code which is:
%you have ndata matrix
[r,c] = size(ndata); %get row and column values of data matrix
fprintf('\nRow of data matrix is: %d' ,r); %print number of row
fprintf('\nColumn of data matrix is: %d ' ,c); %print number of column
채택된 답변
추가 답변 (2개)
Rajashree Jain
2011년 3월 15일
0 개 추천
[val row]=max(A(:));
[val col]=max(A(row,:));
[val row col];
댓글 수: 1
Jan
2011년 3월 15일
This will not work. In the first line you can get e.g. the last element of A as maximum, then "row==numel(A)". Then "A(row, :)" will fail.
Amey
2011년 3월 15일
0 개 추천
The first answer given by Jan Simon is absolutely right and the most efficient way to do it.
카테고리
도움말 센터 및 File Exchange에서 Performance and Memory에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!