Convert Cell to string
2,251 ビュー (過去 30 日間)
古いコメントを表示
I have got a simple question. I want to convert a cell array to a string array, somehow I don't succeed in doing this.
An example:
I' ve got this: a={1650}, which is a cell array. Because I want to concatenate this with other strings I need to convert the cell array to a string array. I have tried many converting functions but I dont get the correct final string array.
Hopefully somebody can help me with this.
Many Thanks.
0 件のコメント
回答 (2 件)
Youssef Khmou
2013 年 2 月 23 日
hi, You can accomplish that by converting the cell to matrix first then coverting the matrix to string array
B=num2str(cell2mat(A));
3 件のコメント
Walter Roberson
2020 年 11 月 12 日
B = cellfun(@val2str, A, 'uniform', 0);
function str = val2str(val)
str = evalc(disp(val));
end
Stephen23
2024 年 1 月 3 日
Or without EVALC, since R2021a:
B = cellfun(@formattedDisplayText, A, 'uni', 0);
Jonathan Thomet
2020 年 11 月 12 日
C = {'Li','Sanchez','Jones','Yang','Larson'}
B = string(C)
That should do the trick.
参考
カテゴリ
Help Center および File Exchange で Data Type Conversion についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!