Results 1 to 5 of 5

Math Help - matrix size in matlab

  1. #1
    Newbie
    Joined
    Nov 2008
    Posts
    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 ???
    Follow Math Help Forum on Facebook and Google+

  2. #2
    Banned
    Joined
    Nov 2008
    Posts
    82

    Arrow

    Quote Originally Posted by rong_en View Post
    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
    Follow Math Help Forum on Facebook and Google+

  3. #3
    Grand Panjandrum
    Joined
    Nov 2005
    From
    someplace
    Posts
    14,972
    Thanks
    4
    Quote Originally Posted by David24 View Post
    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
    Follow Math Help Forum on Facebook and Google+

  4. #4
    Banned
    Joined
    Nov 2008
    Posts
    82
    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)??
    Follow Math Help Forum on Facebook and Google+

  5. #5
    Grand Panjandrum
    Joined
    Nov 2005
    From
    someplace
    Posts
    14,972
    Thanks
    4
    Quote Originally Posted by David24 View Post
    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
    Follow Math Help Forum on Facebook and Google+

Similar Math Help Forum Discussions

  1. Replies: 1
    Last Post: April 5th 2011, 06:21 PM
  2. [MATLAB] Optimization - Reduce Step size?
    Posted in the Math Software Forum
    Replies: 0
    Last Post: September 18th 2009, 11:42 PM
  3. determining matrix size
    Posted in the Advanced Algebra Forum
    Replies: 2
    Last Post: June 23rd 2009, 03:27 PM
  4. Matlab ( Matrix )
    Posted in the Math Software Forum
    Replies: 2
    Last Post: April 6th 2009, 01:32 AM
  5. Replies: 3
    Last Post: March 17th 2009, 11:10 AM

Search Tags


/mathhelpforum @mathhelpforum