max value from particular set of rows and columns

조회 수: 6 (최근 30일)
Ace_ventura
Ace_ventura 2015년 3월 8일
댓글: Image Analyst 2015년 3월 8일
Guys, I have a 12X40 matrix. I want to search for the max value but in certain rows and columns. Say, I want to search for max in first three rows and last three rows and column number 2 5 8 14 16 and35. It should pick the max. from these locations only. I tried a=[1 2 3 10 11 12] b=[2 5 8 14 16 35] c=max(max(matrix(a,b))

답변 (2개)

Image Analyst
Image Analyst 2015년 3월 8일
편집: Image Analyst 2015년 3월 8일
Try this:
matrix = rand(12, 40) % Sample data
a=[1 2 3 10 11 12]
b=[2 5 8 14 16 35]
% Extract only the rows we care about
subMatrix = matrix(a, :);
% Extract only the columns we care about
subMatrix = subMatrix(:, b)
% Find the max in what's left:
theMax = max(subMatrix(:))
  댓글 수: 4
Ace_ventura
Ace_ventura 2015년 3월 8일
I got the answer..Thanks for replying Image Analyst.
Image Analyst
Image Analyst 2015년 3월 8일
Well, yes it should have been the same but you said it didn't work, so in the cases where the obvious method does not work, I break it up into smaller parts, sub-expressions, to make sure each sub-step works properly, so that's what I did. I later ran your code and found that it gave the same answer, so I'm not sure what went wrong.

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


Guillaume
Guillaume 2015년 3월 8일
You've done it the right way, so if it's not giving you the expected result the problem is somewhere else.
Possibly, post the content of your matrix and the result you expect.
  댓글 수: 2
Ace_ventura
Ace_ventura 2015년 3월 8일
i tried it on a randomly generated matrix but did not get the desired result
Ace_ventura
Ace_ventura 2015년 3월 8일
I got the answer dis time.I dont know what went wrong the first time.Thanks Guillaume

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

카테고리

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