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.
0 个评论
回答(1 个)
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 个评论
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 Center 和 File Exchange 中查找有关 Logical 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!