I want to change cell array to string.
105 ビュー (過去 30 日間)
古いコメントを表示
I want to change cell array to string.
I have a 1x6 cell array.
{'abc = 1'}
{'def = 2'}
{'cba = 3'}
{'fed = 4'}
{'sag = 5'}
{'dfg = 6'}
I used strjoin() for this.
abc = 1 def = 2 cba = 3 fed = 4 sag = g dfg = 6
In this way, all characters are connected and printed.
I want to produce the results as below.
abc = 1
def = 2
cba = 3
fed = 4
sag = 5
dfg = 6
0 件のコメント
採用された回答
Voss
2022 年 2 月 28 日
編集済み: Voss
2022 年 2 月 28 日
Here are a few different things you can try, depending on your purposes:
C = {'abc = 1' 'def = 2' 'cba = 3' 'fed = 4' 'sag = 5' 'dfg = 6'}
% 2D character array, only works if all elements of C are the same length
char_array = vertcat(C{:})
% string array:
str = string(C.')
str = string(C(:))
% column vector cell array
cell_column = C.'
cell_column = C(:)
% just print the original cell array
fprintf('%s\n',C{:})
0 件のコメント
その他の回答 (1 件)
Arif Hoq
2022 年 2 月 28 日
try this:
A=[{'abc = 1'},{'def = 2'},{'cba = 3'},{'fed = 4'},{'sag = 5'},{'dfg = 6'}];
str=string(A)';
fprintf('\n%s\n',str);
1 件のコメント
Stephen23
2022 年 2 月 28 日
Converting to string is completely superfluous, as _'s answer correctly shows:
C = {'abc = 1' 'def = 2' 'cba = 3' 'fed = 4' 'sag = 5' 'dfg = 6'};
fprintf('%s\n',C{:})
参考
カテゴリ
Help Center および File Exchange で Characters and Strings についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!