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.

답변 (1개)

dpb
dpb 2017년 5월 4일

0 개 추천

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일
편집: Ahmed Hossam 2017년 5월 4일
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??

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Cell Arrays에 대해 자세히 알아보기

질문:

2017년 5월 4일

댓글:

dpb
2017년 5월 4일

Community Treasure Hunt

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

Start Hunting!

Translated by