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...
0 个评论
回答(1 个)
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 个评论
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 Exchange 中查找有关 Loops and Conditional Statements 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!