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일

0 개 추천

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

Fei Li
Fei Li 2018년 11월 1일
Hi Thanks for your answer. I want a string array. I think this way may be more easy to understand: I have a cell, but have different dimensions. some has 1xN, some are 1xM. I try with strsplit and your way. those function can convert 1xM single cell to a string array. But they can't concatenate to a string array because of the inconsistent dimensions.
Guillaume
Guillaume 2018년 11월 1일
편집: Guillaume 2018년 11월 1일
Still have no idea what you want. You tell use what doesn't work but not what the result should be. Let's be concrete. Given the cell array:
c = {["a", "bbbb"], ["cc", "dddd", "e"]} %cell array with string arrays of different size
What do you want as output? Exact answer in valid matlab syntax please.
Fei Li
Fei Li 2018년 11월 1일
strarray=["a","bbbb";"cc","dddd","e"]
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일

2 개 추천

What happens when you do?
cellstr()

댓글 수: 5

Fei Li
Fei Li 2018년 11월 1일
It reports an error "Error using cellstr (line 44) Element 1 is not a string scalar or character array. All elements of cell input must be string scalars or character arrays."
madhan ravi
madhan ravi 2018년 11월 1일
I think the contents in your cells are strings
Fei Li
Fei Li 2018년 11월 1일
Yes, they are strings have different dimensions.
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.

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Cell Arrays에 대해 자세히 알아보기

질문:

2018년 11월 1일

댓글:

2018년 11월 2일

Community Treasure Hunt

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

Start Hunting!

Translated by