cell配列の中の文字を結合する方法

a={'abc'};
b={'def'};
というそれぞれの変数を結合して
c={'abcdef'}といったcell配列を作成したいです。
joinやappend関数をしようと試みていますが、
"(タイプ'cell' の入力引数) が未定義です。"といったエラーが出てしまいます。
どのようにすれば結合できるかご教示いただけないでしょうか?

 Accepted Answer

Atsushi Ueno
Atsushi Ueno on 2 Dec 2022
Edited: Atsushi Ueno on 2 Dec 2022
append 関数の引数は str = append(str1,...,strN) の様に可変個であるのに対し、
join 関数の入力は newStr = join(str,delimiter,dim)の様に入力文字列を一つにする必要があります。
また join 関数の引数 delimiter — string の結合に使用する区切り記号 はデフォルト値がスペース文字なので、これを空の文字ベクトル(または空の string 配列)に変更しないと、結合結果が {'abc def'} になってしまいます。
a = {'abc'}; b = {'def'}; c = {'abcdef'}; % 求める結果はc
c1 = join([a,b],'')
c1 = 1×1 cell array
{'abcdef'}
c2 = append(a,b)
c2 = 1×1 cell array
{'abcdef'}

More Answers (0)

Categories

Products

Release

R2016b

Asked:

on 2 Dec 2022

Edited:

on 2 Dec 2022

Community Treasure Hunt

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

Start Hunting!