How can I find a sub matrix of a matrix (of any size) where this happens:(Homework question)

조회 수: 1 (최근 30일)
For example:
A = [21 25 -5 4; 21 25 -5 4; 22 26 21 22; 21 25 25 26; 21 25 -5 21];
the sub matrix of A is
B = [21 25 -5; 22 26 21];
Both B and B' are sub arrays of A
I can use size and length functions only...

답변 (1개)

Matt J
Matt J 2013년 1월 6일
편집: Matt J 2013년 1월 6일
Hint: First I would concentrate on the special case B=A. How would you test equality between A and B without using commands like ALL, ISEQUAL, etc...? Once you've solved that part, you can just loop over all submatrices and apply the same comparison function.
I'm assuming you are allowed to use for-loops and math operators like &, +, -, ==, etc... even though there are functions that these operators call. Otherwise, I think the whole thing is impossible.
  댓글 수: 2
Zaza
Zaza 2013년 1월 6일
B=A if A is symmetric
do i need to use nested for-loops?
Image Analyst
Image Analyst 2013년 1월 6일
Yes, four of them should do it. One to move the rectangular window (the size of B or B') along rows and columns of A, and inside that nested pair of for loops, another pair to check the values of A inside the window for matches with corresponding elements of B and B'. Make sure you calculate the starting and stopping indexes of the for loop correctly so that you don't go outside the arrays.

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

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by