Adding a cell to another cell in a specific position

I have two cells:
A(n x 1)
B(m x 1)
I'd like to add cell B to cell A in a specific position of A.
Do you have any suggestion?

 採用された回答

Rik
Rik 2021 年 3 月 29 日

0 投票

What do you mean exactly by adding?
%create some data
n=3;m=5;
A=num2cell(1:n).';
B=num2cell(2*n+(1:m)).';
%option 1:
A1=A;
A1{2}=B;
disp(A1)
{[ 1]} {5×1 cell} {[ 3]}
%option 2:
k=2;A2=A;
A2=[A2(1:k);B;A2((k+1):end)];
disp(A2)
{[ 1]} {[ 2]} {[ 7]} {[ 8]} {[ 9]} {[10]} {[11]} {[ 3]}

2 件のコメント

Francesca Danielli
Francesca Danielli 2021 年 3 月 29 日
Thank you!
Option 2 works!
Rik
Rik 2021 年 3 月 29 日
If my answer solved your issue, please consider marking it as accepted answer. If not, feel free to comment with your remaining questions.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeData Type Conversion についてさらに検索

質問済み:

2021 年 3 月 29 日

コメント済み:

Rik
2021 年 3 月 29 日

Community Treasure Hunt

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

Start Hunting!

Translated by