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

1 Ansicht (letzte 30 Tage)
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...

Antworten (1)

Matt J
Matt J am 6 Jan. 2013
Bearbeitet: Matt J am 6 Jan. 2013
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 Kommentare
Image Analyst
Image Analyst am 6 Jan. 2013
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.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by