Merge array cells after creation to one cell

Hi,
i have an array arr = cell(2,3) and I wonder, if there's a method/function/trick which could combine the three cells in the second row into just one cell?
I mean instead of having:
arr =
[?] [?] [?]
[?] [?] [?]
I would like to have:
arr =
[?] [?] [?]
[ ? ]
I tried to use reshape, but using reshape restricts the user to keep the number of cells unchanged. With this I am changing the size of the array along its second dimension ... Is this possible?
I ask because in the last row of my cell array, I just need one cell and not any more:
Thanks for your answer in advance.

Answers (1)

No. The cell array is required to be rectangular; the content of some cell can be empty as you have, but the cell array itself can't be jagged.
>> c=cell(2) % build a minimal cell array
c =
[] []
[] []
>> c(4)=[] % try to shorten the second row
c =
[] [] []
>>
As you see, Matlab has let you eliminate the cell, but it now is a vector, not 2D array.
You could encapsulate each row into another cell that can be variable-length, but that's another level of indirection in addressing to get to the data.
Where's the problem, specifically, as is other than simply the visual representation isn't neat?

3 Comments

I just wanted to know if it would be possible for a cell array to change its rectangular form after creation...
It would have nice, but if it's not possible, then I get the point. No problem!
No, the underlying cell array itself must be rectangular; the content in each cell is variable including empty, but the empty placeholder is something so the cell itself isn't (empty that is).
>> c=cell(2);
>> isempty(c)
ans =
0
>> isempty(c(1))
ans =
0
>> isempty(c{1})
ans =
1
>>
If that's the nub of the question, how about Accept'ing an Answer to at least indicate query isn't still outstanding??

Sign in to comment.

Categories

Asked:

on 4 May 2017

Commented:

dpb
on 4 May 2017

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!