Finding the corresponding number in a matrix

I need to find a number in one column that corresponds with a different column. For example: [1 2 4 6 10 9; 3 5 7 2 8 6], I want the max in column 1, which is ten, I also want to find 8 in the second column.

답변 (2개)

Image Analyst
Image Analyst 2022년 9월 11일
Did you look up max in the help?
m = [1 2 4 6 10 9; 3 5 7 2 8 6]
m = 2×6
1 2 4 6 10 9 3 5 7 2 8 6
% Find maxes in each of the 2 rows (consisting of 6 columns):
maxesOfRows = max(m, [], 2)
maxesOfRows = 2×1
10 8
% Find maxes in each of the 6 columns (consisting of 2 rows):
maxesOfColumns = max(m, [], 1)
maxesOfColumns = 1×6
3 5 7 6 10 9

댓글 수: 2

jason
jason 2022년 9월 11일
what if it was a 5 instead of an 8?
then you would use the code I suggested.

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

Walter Roberson
Walter Roberson 2022년 9월 11일

0 개 추천

m = [1 2 4 6 10 9; 3 5 7 2 8 6]
[~, idx] = max(m(1,:));
m(2,idx)

카테고리

도움말 센터File Exchange에서 Logical에 대해 자세히 알아보기

제품

릴리스

R2022a

태그

질문:

2022년 9월 11일

댓글:

2022년 9월 11일

Community Treasure Hunt

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

Start Hunting!

Translated by