Asked by Miguelcm90
on 3 Sep 2013

Hi everybody, I would like to divide a matrix, in three smaller matrix with the same number of n columns but rows are m/c, being c the number of parts I want to divide this matrix. So, taking in consideration I use this file,

https://www.dropbox.com/s/1wav4fb1afqx8ix/validx.txt

I would like to mke a loop with condition so as to divide and save this new matrix in a new file or variable to work with it more easily.

I would load the file.dat and read the matrix, run a for loop and read al values, and save them in new three matrix. I am sorry because I am starting to use MATLAB:

Thanks in advance

Best Regards,

*No products are associated with this question.*

Answer by Matt J
on 3 Sep 2013

You could use MAT2TILES ( Available Here ).

Example:

m=12; n=10; c=3;

A=rand(m,n);

C=mat2tiles(A,[m/c,inf])

leads to three matrices C{1}, C{2}, C{3} that are 4x10,

C =

[4x10 double] [4x10 double] [4x10 double]

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi test

Learn moreOpportunities for recent engineering grads.

Apply Today
## 1 Comment

## dpb (view profile)

Direct link to this comment:http://www.mathworks.com/matlabcentral/answers/86244#comment_167163

Why not simply read the array and then operate on the pieces desired?

If you set the number to look at a time either as a user input or a constant, then a function could be called from a loop using something like

There are more sophisticated ways in Matlab you'll learn w/ time but that's the essence of how to work with arrays in Matlab --

don'tstart creating new variables willy-nilly; work with the array indices and sub-arrays and the like is much more productive.