Text variable in 'cell' data type.

1 次查看(过去 30 天)
I'm trying to read a text variable from a .csv file into desktop Matlab 2015a. Matlab reads it as a 'cell' type. Is there a way to convert the cell into a matrix, or have Matlab read the data directly into a matrix type? I'm using the data importation wizard. I've tried 'cell2table' and then converting the table to something useful with 'table2array' but that gives me back a cell again. I've also tried subsetting with differing kinds of brackets, but can only get the first or last entry that way.
  1 个评论
James Tursa
James Tursa 2015-9-18
编辑:James Tursa 2015-9-18
Please post a short example of your code so we can comment on it and offer suggestions or corrections. Accessing the contents of the cell is done with the curly { } brackets.

请先登录,再进行评论。

采纳的回答

Kirby Fears
Kirby Fears 2015-9-18
编辑:Kirby Fears 2015-9-18
Hi Simon,
The cell2mat function will attempt to convert your cell into a matrix. If your csv file contains mixed data (some numeric data and some strings), you will need to isolate the numeric part first.
Below is an example of extracting the numeric part of a cell.
C={'date','value','other';1,3,5;3,2,1}
numC=cell2mat(C(2:end,:));
You can also try the readtable function. If your csv file contains a matrix of data with column headers on top, it should give you a nice table in your workspace where the numeric data can be easily extracted into an array if necessary.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Data Type Conversion 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by