# Thread: matrix size in matlab

1. ## matrix size in matlab

hi,

i get a 1 by 1000 matrix, say A.

how to change it into a 100 by 10 matrix in matlab ???

2. Originally Posted by rong_en
hi,

i get a 1 by 1000 matrix, say A.

how to change it into a 100 by 10 matrix in matlab ???
All depends upon how you want to reshape your vector,

I'm assuming you have a vector with dimension n*m x 1 that you want to transform into a n x m matrix

If this is correct, you can use the reshape command (type 'help reshape' into the Command Window for further info) which in your case would be

A = reshape(your_vector,m,n);

I dont have matlab on this PC so Im not sure if it allocates columnwise or rowwise, but if the above doesnt work, then it should be
A = reshape(your_vector,n,m)

Alternatively you would always script a simple piece of code to do it
(either in the Command Window or a simple m-file)

for i = 1:1:10
A(:,i) = your_vector(100*(i-1) + 1 : 100*i);
end

you can preallocate the matrix A first if you want to (i.e. above the for statement include A = zeros(100,10)

Hope this helps,

David

3. Originally Posted by David24
All depends upon how you want to reshape your vector,

I'm assuming you have a vector with dimension n*m x 1 that you want to transform into a n x m matrix

If this is correct, you can use the reshape command (type 'help reshape' into the Command Window for further info) which in your case would be

A = reshape(your_vector,m,n);

I dont have matlab on this PC so Im not sure if it allocates columnwise or rowwise, but if the above doesnt work, then it should be
A = reshape(your_vector,n,m)

Alternatively you would always script a simple piece of code to do it
(either in the Command Window or a simple m-file)

for i = 1:1:10
A(:,i) = your_vector(100*(i-1) + 1 : 100*i);
end

you can preallocate the matrix A first if you want to (i.e. above the for statement include A = zeros(100,10)

Hope this helps,

David
Not as complete as the student edition of Matlab but FreeMat is pretty good and can be fooled into not needing installation, so can be run off of a pen-drive (memory stick, ...)

(I would mention Octave, but I have not found a method of running it off of a pen-drive)

CB

4. CaptainBlack,

Cheers for the info, have you every used Scilab?? Not a bad free alternative to matlab!

Thanks again,

David

ps - Have you done much OOP in Matlab (new feature released in R2008a)??

5. Originally Posted by David24
CaptainBlack,

Cheers for the info, have you every used Scilab?? Not a bad free alternative to matlab!

Thanks again,

David

ps - Have you done much OOP in Matlab (new feature released in R2008a)??
Yes I have, and it's nice particularly because of Scicos (not a simulaink clone but similar). I don't use it normally because its syntax is slightly but significantly different from matlab, and its DSP tools.

No I never use the OOP features, its not relevant to how I use Matlab. (In fact I usualy don't use Matlab because it is so big and clunky these days, I prefer Euler (which I build from source) which (my build anyway) is small and fast booting.

CB