Error using when cell2mat (with string characters)

40 ビュー (過去 30 日間)
Thomas Côté
Thomas Côté 2019 年 6 月 11 日
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 Center および File ExchangeData Type Conversion についてさらに検索

製品


リリース

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by