Concatenate cells leaving columns/rows empty

If I want to concatenate 2 cells I can use []. For example:
>> a={'lala'};b={'lolo'};c=[a,b]
c =
1×2 cell array
{'lala'} {'lolo'}
However, if I want to leave a column (or row if I'd had concatenated them vertically) empty, I have to create an empty array to "occupy" the space:
>> d=cell(1,1);
>> c=[d,a,b]
c =
1×3 cell array
{0×0 double} {'lala'} {'lolo'}
I have not been able to change the position of a and b without creating the empty cell. Is there a way to choose their position just by indexing? I don't really care what the "empty cell" is.

 채택된 답변

Guillaume
Guillaume 2019년 11월 7일

0 개 추천

Do you mean this:
c = {}; %or better if you know the final size:
%c = cell(1, 3);
c(1, [1 3]) = [a,b]; %put a at column 1 and b at column 3
?

댓글 수: 3

Miquel
Miquel 2019년 11월 7일
Yes! Thanks :)
Although I'm still playing wit it, I think I understand how to use it. However I don't get why it works and would have never done it myself. Could you tell me the logic behind it, please?
Guillaume
Guillaume 2019년 11월 7일
It's a simple assignment using indexing. As long as the left-hand and right-hand side have the same size (or the right-hand side is scalar) it just work.
c(1, [1 3]) is a two-element portion of the destination cell array to which you assign a two-element cell array.
Miquel
Miquel 2019년 11월 7일
Thanks!

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

추가 답변 (0개)

카테고리

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

제품

릴리스

R2018b

질문:

2019년 11월 7일

댓글:

2019년 11월 7일

Community Treasure Hunt

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

Start Hunting!

Translated by