MATLAB: combine two cell arrays of string at a specific position

2 ビュー (過去 30 日間)
Senanu Sania
Senanu Sania 2022 年 1 月 5 日
編集済み: Dave B 2022 年 1 月 5 日
I have two cells of strings: A(a,1) and B(b,1), where a>b. I want to combine A with B, adding B at a certain position of A. Notice that in A there are no blank rows, so I suppose that first I have to add b blank rows in A and then concatenate B at a specific position.

回答 (1 件)

Dave B
Dave B 2022 年 1 月 5 日
編集済み: Dave B 2022 年 1 月 5 日
If I understand the question correctly, you can just specify the indices where you want your strings to go.
A={'Moose';'Goose';'Horse';'Pig'}
A = 4×1 cell array
{'Moose'} {'Goose'} {'Horse'} {'Pig' }
B={'Dog';'Cat'}
B = 2×1 cell array
{'Dog'} {'Cat'}
pos = 3; % insert B starting at A's third index
A=[A(1:pos-1);B;A(pos:end)]
A = 6×1 cell array
{'Moose'} {'Goose'} {'Dog' } {'Cat' } {'Horse'} {'Pig' }

カテゴリ

Help Center および File ExchangeCell Arrays についてさらに検索

タグ

製品


リリース

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by