put a some small matrix in a big matris

1 view (last 30 days)
I have a problem. I have a big matrix that in each loop I search for some data that satisfy some conditions. The result of "find" will be a small matrix that can vary in size. I want to put this small matrix in a for example 100*100 zeros matrix. so my problem is: suppose at first iteration I have a 3*4 matrix that I want to be placed in the top left corner of the big matrix. I want to keep the small matrix arrangement. I mean I do not want to reshape the small matrix. in the next iteration, I have another small matrix that I want to be placed exactly next to previous small matrix in the big matrix. I want my program to be able to recognize to put for example the small matrix obtained by 5th iteration at next zero row. Could anyone please help me to do that without lots of "for-if"?

Accepted Answer

Walter Roberson
Walter Roberson on 30 May 2012
Just keep a running total of the number of rows you have filled so-far, and place the next matrix starting from the next row.
This assumes you always want to place the next underneath the previous. If you want to place as many as possible to the right that fit inside the width, and then move down to the next available row, then the logic would be a little different: in that case the next available row is your starting row plus the maximum number of rows of what you just placed across.

More Answers (0)

Categories

Find more on Operators and Elementary Operations in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!