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

Printable View

- June 22nd 2010, 04:30 PMnarutoAdd 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 - June 22nd 2010, 04:32 PMundefined
- June 22nd 2010, 04:44 PMnaruto
O ya! Sorry I am new. Matlab.

- June 22nd 2010, 04:54 PMundefined
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." - June 22nd 2010, 08:30 PMnarutoNot 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? - June 22nd 2010, 08:56 PMundefined
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) = { [] };`

- June 22nd 2010, 09:05 PMnaruto
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... :/

- June 22nd 2010, 09:14 PMundefined
I read some more.. try

Code:`bananas(4,1:4) = {1, 2, 3, 4};`

Code:`bananas(4,1) = { [] };`

EDIT: You could try this too

Code:`bananas(4,:) = {1, 2, 3, 4};`

- June 22nd 2010, 10:14 PMnarutoWorks
Thank you so much for your time! it worked!

:)