1. ## 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

2. Originally Posted by naruto
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?

3. O ya! Sorry I am new. Matlab.

4. Originally Posted by naruto
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."

5. ## 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?

6. Originally Posted by naruto
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.

7. 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... :/

8. Originally Posted by naruto
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... :/

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.

9. ## Works

Thank you so much for your time! it worked!

,

,

,

,

,

,

,

,

,