フィルターのクリア

How can I concatenate a string array of a dimension 1x N into one cell

4 ビュー (過去 30 日間)
Carlos Quispe Galdos
Carlos Quispe Galdos 2022 年 7 月 12 日
Hello community,
I want to accomplish the following with my code:
  • Originally I don't know the number of names in array A and I have to group them in just one cell concatenating them with the delimiter "/". I tried the for loop with no success and it is not necessary at all. Any hints on how I can accomplish this? I appreciate all the help.
  1 件のコメント
Stephen23
Stephen23 2022 年 7 月 12 日
As well as JOIN() as Chunru showed here are a few other approaches:
A = {'ABC','DEF','HIJK'};
B = char(join(A,'/'))
B = 'ABC/DEF/HIJK'
C = sprintf('/%s',A{:});
C = C(2:end)
C = 'ABC/DEF/HIJK'
D = cell2mat(strcat('/',A));
D(1) = []
D = 'ABC/DEF/HIJK'
A(2,1:end-1) = {'/'};
E = [A{:}]
E = 'ABC/DEF/HIJK'

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

採用された回答

Chunru
Chunru 2022 年 7 月 12 日
編集済み: Chunru 2022 年 7 月 12 日
% using cell array of char
A = {'ABC', 'DEF', 'HIJK'}
A = 1×3 cell array
{'ABC'} {'DEF'} {'HIJK'}
B = join(A, '/')
B = 1×1 cell array
{'ABC/DEF/HIJK'}
% using string
C = string(A)
C = 1×3 string array
"ABC" "DEF" "HIJK"
C = join(C, '/')
C = "ABC/DEF/HIJK"

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCharacters and Strings についてさらに検索

製品


リリース

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by