Results 1 to 9 of 9

Math Help - Add new row to cell array

  1. #1
    Newbie
    Joined
    Jun 2010
    Posts
    9

    Question Add new row to cell array

    How do I go about adding a new row to a cell array? For example, if i have a 3x4 cell array and then i want to add a new row so it is a 4x4 cell array. It is probably really simple and i just can't get it... haha

    Thanks,
    Naruto
    Follow Math Help Forum on Facebook and Google+

  2. #2
    MHF Contributor undefined's Avatar
    Joined
    Mar 2010
    From
    Chicago
    Posts
    2,340
    Awards
    1
    Quote Originally Posted by naruto View Post
    How do I go about adding a new row to a cell array? For example, if i have a 3x4 cell array and then i want to add a new row so it is a 4x4 cell array. It is probably really simple and i just can't get it... haha

    Thanks,
    Naruto
    Care to name the software/language you are using?
    Follow Math Help Forum on Facebook and Google+

  3. #3
    Newbie
    Joined
    Jun 2010
    Posts
    9
    O ya! Sorry I am new. Matlab.
    Follow Math Help Forum on Facebook and Google+

  4. #4
    MHF Contributor undefined's Avatar
    Joined
    Mar 2010
    From
    Chicago
    Posts
    2,340
    Awards
    1
    Quote Originally Posted by naruto View Post
    O ya! Sorry I am new. Matlab.
    No problem! (And welcome!) I don't have access to MATLAB at the moment, but I found this reference.

    "MATLAB expands the size of the cell array with each assignment statement... If you assign data to a cell that is outside the dimensions of the current array, MATLAB automatically expands the array to include the subscripts you specify. It fills any intervening cells with empty matrices."
    Follow Math Help Forum on Facebook and Google+

  5. #5
    Newbie
    Joined
    Jun 2010
    Posts
    9

    Not working...

    First some background... bananas is a 3x4 cell array and i want to add a new row with 4 columns so it becomes a 4x4.

    So I add this to it using this code:

    bananas = {bananas;{1, 2, 3, 4}}

    But when i look at the info of the cell array it tells me that is is just a 3x4 on top of a 1 x 4. Is there anyway to get as one big cell array that is 4x4?
    Follow Math Help Forum on Facebook and Google+

  6. #6
    MHF Contributor undefined's Avatar
    Joined
    Mar 2010
    From
    Chicago
    Posts
    2,340
    Awards
    1
    Quote Originally Posted by naruto View Post
    First some background... bananas is a 3x4 cell array and i want to add a new row with 4 columns so it becomes a 4x4.

    So I add this to it using this code:

    bananas = {bananas;{1, 2, 3, 4}}

    But when i look at the info of the cell array it tells me that is is just a 3x4 on top of a 1 x 4. Is there anyway to get as one big cell array that is 4x4?
    To be honest I have never used MATLAB (it costs $ and I haven't had access); however, I know several programming languages and some CAS's.. so going purely off of documentation, I'd say to try

    Code:
    bananas(4,1) = { [] };
    If that doesn't work, someone who's actually used MATLAB should notice this thread eventually and be able to tell you.
    Follow Math Help Forum on Facebook and Google+

  7. #7
    Newbie
    Joined
    Jun 2010
    Posts
    9
    Ok that works perfectly but now trying to set values to bananas(4,1),bananas(4,2),bananas(4,3),bananas(4,4 ) at once is the tricky part that i am trying to do... :/
    Follow Math Help Forum on Facebook and Google+

  8. #8
    MHF Contributor undefined's Avatar
    Joined
    Mar 2010
    From
    Chicago
    Posts
    2,340
    Awards
    1
    Quote Originally Posted by naruto View Post
    Ok that works perfectly but now trying to set values to bananas(4,1),bananas(4,2),bananas(4,3),bananas(4,4 ) at once is the tricky part that i am trying to do... :/
    I read some more.. try

    Code:
    bananas(4,1:4) = {1, 2, 3, 4};
    and if this works, there should be no need to use

    Code:
    bananas(4,1) = { [] };
    unless you want the fourth row to be empty.

    EDIT: You could try this too

    Code:
    bananas(4,:) = {1, 2, 3, 4};
    This might be valid short-hand.
    Follow Math Help Forum on Facebook and Google+

  9. #9
    Newbie
    Joined
    Jun 2010
    Posts
    9

    Works

    Thank you so much for your time! it worked!

    Follow Math Help Forum on Facebook and Google+

Similar Math Help Forum Discussions

  1. Matlab - cell array
    Posted in the Math Software Forum
    Replies: 0
    Last Post: April 3rd 2010, 06:28 AM
  2. Matlab data cleaning - cell array to matrix problem
    Posted in the Math Software Forum
    Replies: 0
    Last Post: March 24th 2010, 10:08 AM
  3. Peaucellier's cell
    Posted in the Advanced Math Topics Forum
    Replies: 0
    Last Post: March 10th 2010, 01:43 PM
  4. cell division
    Posted in the Calculus Forum
    Replies: 0
    Last Post: October 25th 2007, 07:11 PM
  5. Cell phone
    Posted in the Statistics Forum
    Replies: 0
    Last Post: February 26th 2006, 03:51 PM

Search Tags


/mathhelpforum @mathhelpforum