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

1 回表示 (過去 30 日間)
Zaza
Zaza 2013 年 1 月 6 日
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 Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by