Problem 44350. Breaking Out of the Matrix
Do you want to take the Red Pill, or the Blue Pill?
If you take the Blue Pill, you will simply pass along to the next problem, not knowing what Cody has in store for you.
If you take the Red Pill, you will be asked to write a MATLAB function that will Break a Matrix. The inputs to the function will be a matrix M, along with a number of rows (R) and columns (C). You goal is to break the larger 2-D matrix up into a 3-D matrix comprised of enough RxC matrices so that you can recreate the 2-D matrix. When creating your 3-D matrix, go down the columns first, and then across the rows. Increment only one column (or one row) at a time. Do not go C columns down at each step.
For example, R=2 and C=3, and M is as follows:
M=[1 4 7 10 2 5 8 11 3 6 9 12]
This means that your output should be a 2x3x4 matrix:
X(:,:,1) = 1 4 7 2 5 8 X(:,:,2) = 2 5 8 3 6 9 X(:,:,3) = 4 7 10 5 8 11 X(:,:,4) = 5 8 11 6 9 12
You can assume that R and C will always be less than or equal to the appropriate dimension of the original matrix. Good luck!
Solution Stats
Problem Comments
-
14 Comments
to help clarify (not really) one application would be in convolutional networks, where for an input image M you might want to find the list X of all image blocks of size R*C (and R=C=1 is just a extreme case where you end up listing individual pixels)
Hi,
in my opinion this problem need a clarification, i.e. you have to move along columns and rows by incrementing only one row or one column each time.
It may sound obvious but I lost a lot of time solving the wrong problem, i.e. I moved along column first and row after, by incrementing each time by R and C.
I added a couple more sentences in the description to (hopefully) clear things up for people who were having the same problem you did, M.M.A.
Solution Comments
Show commentsProblem Recent Solvers355
Suggested Problems
-
It dseon't mettar waht oedrr the lrettes in a wrod are.
1898 Solvers
-
830 Solvers
-
5476 Solvers
-
5663 Solvers
-
119 Solvers
More from this Author80
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!