Convert cell to string

21 ビュー (過去 30 日間)
Fei Li
Fei Li 2018 年 11 月 1 日
コメント済み: Fei Li 2018 年 11 月 2 日
I have a cell (721*1), each cell composed by a different number of string, for example, the first cell is a (1*20) string. I want to convert this cell to string. when I use string function, it reported an error as "Conversion from cell failed. Element 1 must be convertible to a string scalar.". I have no idea why it can't convert as the string function described in Matlab.

採用された回答

Guillaume
Guillaume 2018 年 11 月 1 日
So what is that conversion from cell array to string supposed to do? What do you want as an output?
Assuming it's a 1xN string array that is simply the concatenation of all the string arrays in your cell array, then:
sarray = [A{:}]
The above will fail if at least one string array in any cell does not have the same number of rows as all the other string arrays.
  5 件のコメント
Guillaume
Guillaume 2018 年 11 月 1 日
That is not possible and what you wrote would produce an error in matlab. string arrays like all arrays must have the same number of elements in each row.
You cannot vertically concatenate string row vectors of different size. You can however horizontally concatenate them and my original answer did just that.
Fei Li
Fei Li 2018 年 11 月 2 日
Yes, I understand now. Thanks for your time. Really appreciated.

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

その他の回答 (1 件)

madhan ravi
madhan ravi 2018 年 11 月 1 日
編集済み: madhan ravi 2018 年 11 月 1 日
What happens when you do?
cellstr()
  5 件のコメント
madhan ravi
madhan ravi 2018 年 11 月 1 日
If they are strings why do you want to convert them?
Fei Li
Fei Li 2018 年 11 月 1 日
but they are in a cell. I want a string array. Is that possible? anyway, thanks to all your help.

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

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by