Why is cell2mat returning a char array and not an ordinary array?
조회 수: 15 (최근 30일)
이전 댓글 표시
In the documentation it says cell2mat returns an ordinary array, but when I use it I get a n x n char array. Does anyone know how to make it do what it says it should do?
Thanks
댓글 수: 0
채택된 답변
Azzi Abdelmalek
2015년 7월 31일
Kim what is an ordinary array? array of string doesn't exist in Matlab.
s={'ab' 'cd';'er','mh'}
cell2mat(s)
Result
ans =
abcd
ermh
If the cells are different sizes, cell2mat doesn't work
If you have a cell of numbers n={12 145;62 78}. There is no problem
n={12 145;62 78}
cell2mat(n)
추가 답변 (1개)
Image Analyst
2015년 7월 31일
Because character arrays are what's inside your cells. See the FAQ: http://matlab.wikia.com/wiki/FAQ#What_is_a_cell_array.3F
To use cell2mat with arrays, they have to be the same size, as Azzi said. If they're different sizes, you can use char() and it will create a rectangular array and pad it with spaces.
s={'two' 'abcd'; 'three','lotsOfChars'}
sArray = char(s)
참고 항목
카테고리
Help Center 및 File Exchange에서 Cell Arrays에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!