Merge array cells after creation to one cell
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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 comentarios
Respuestas (1)
dpb
el 4 de Mayo de 2017
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 comentarios
dpb
el 4 de Mayo de 2017
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??
Ver también
Categorías
Más información sobre Logical en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!