Merge array cells after creation to one cell

2 次查看(过去 30 天)
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.

回答(1 个)

dpb
dpb 2017-5-4
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 个评论
Ahmed Hossam
Ahmed Hossam 2017-5-4
It would have nice, but if it's not possible, then I get the point. No problem!
dpb
dpb 2017-5-4
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??

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Logical 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by