필터 지우기
필터 지우기

How to select a sub square matrix, from a matrix; given the size of the sub square matrix and middle element

조회 수: 2 (최근 30일)
M = [
82 10 16 15 66 76
91 28 98 43 4 75
13 55 96 92 85 40
92 96 49 80 94 66
64 97 81 96 68 18 ]
i need sub sqaure matrices, given size ofthe sub matrix and middle element.
  댓글 수: 4
Walter Roberson
Walter Roberson 2020년 8월 9일
You did not really answer the question though. Is the requirement to locate the center of the matrix according to a given value? Or would you instead be given a position ?
MANOGNA POTLURI
MANOGNA POTLURI 2020년 8월 9일
I'm sorry I didn't get the question first time;
yes, I have the value of the middle element, and I have to find it in the matrix and use that as the centre of the submatrix to extract

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

채택된 답변

Walter Roberson
Walter Roberson 2020년 8월 9일
편집: Walter Roberson 2020년 8월 9일
use find() with two output arguments to get the row and column of the center. Then use indexing like row-something:row+something
You need to make some decisions about how to handle the case of a matrix size that is even. For example if you are asked to return a 2 x 2 matrix relative to the value 4, then how would you resolve that?
You also need to make decisions about the case where the value is found close to an edge of the matrix, and decisions about the case where the value is found multiple times. Also decisions about the case where a larger array is asked for than the size of the original matrix.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by