Error using when cell2mat (with string characters)

조회 수: 39 (최근 30일)
Thomas Côté
Thomas Côté 2019년 6월 11일
댓글: Hussein Hasan Mohsen 2020년 12월 6일
Hi, I have the following cell array that I would like to convert into a matrix with cell2mat() :
Matrix =
7×1 cell array
{'Longueur d''onde' }
{'Position 0.txt' }
{'Position_12500.txt'}
{'Position_15015.txt'}
{'Position_19000.txt'}
{'Position_4200.txt' }
{'Position_9100.txt' }
However, I get the following error :
Error using cat
Dimensions of arrays being concatenated are not consistent.
Error in cell2mat (line 83)
m{n} = cat(1,c{:,n});
It surely has something to do with the string characters, but I'm clueless at what I should do.
Thanks for your help!
  댓글 수: 2
the cyclist
the cyclist 2019년 6월 11일
편집: the cyclist 2019년 6월 11일
There is some confusion in this question, mainly the loose terminology about data types.
So, to clarify ...
A "matrix" is a two-dimensional array, and can only hold numeric values -- not characters, text, strings, etc.
A character array and a string (or an array of strings) are not the same thing, although both of those data types can hold text.
Cell arrays are yet another data type. They are often used as a container for different data types.
(Admittedly, it can be confusing.)
So, your variable that is named Matrix is a cell array, where each cell contains a character array. Your variable Matrix is not a matrix, and its contents cannot be converted into a matrix, because it has non-numeric data.
So, maybe you can add a comment htere, and clarify what data type you want the output to be, and what the contents should look like.
I hope that helps.
Thomas Côté
Thomas Côté 2019년 6월 11일
편집: Thomas Côté 2019년 6월 11일
Thanks for your help!
Indeed, I shouldn't have used Matrix as the name of the cell array.
However, you answered my underlying question to all of that, which was what kind of data can we put into a MAT type and that's only numeric values. I'll just have to proceed differently.
(edited) Silly me, i wanted to play with the characters inside the "Matrix" as if they were numeric values, but I'll have to use structures or strings instead.
Have a great day!

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

채택된 답변

Matt J
Matt J 2019년 6월 11일
편집: Matt J 2019년 6월 11일
Try
char(Matrix)
or
string(Matrix)

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Data Type Conversion에 대해 자세히 알아보기

제품


릴리스

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by