How can I find a sub matrix of a matrix (of any size) where this happens:(Homework question)
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaires
Réponses (1)
Matt J
le 6 Jan 2013
Modifié(e) : Matt J
le 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 commentaires
Image Analyst
le 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.
Voir également
Catégories
En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!