Error using when cell2mat (with string characters)

42 visualizzazioni (ultimi 30 giorni)
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 Commenti
the cyclist
the cyclist il 11 Giu 2019
Modificato: the cyclist il 11 Giu 2019
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é il 11 Giu 2019
Modificato: Thomas Côté il 11 Giu 2019
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!

Accedi per commentare.

Risposta accettata

Matt J
Matt J il 11 Giu 2019
Modificato: Matt J il 11 Giu 2019
Try
char(Matrix)
or
string(Matrix)

Più risposte (0)

Categorie

Scopri di più su Data Type Conversion in Help Center e File Exchange

Prodotti


Release

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by