convert data celll array to double array and write to .xls or .csv

1 次查看(过去 30 天)
Hi,
I have a data cell array "Data" which has 10 cells but each cell have different number of rows (see the image below). Can anybody suggest me a way to store in a "example" double array like this below.?
This is an example of 10 cells but I have 200 cells like this the same way alternatively changes row numbers following the same pattern.
example =
col1 col2 col3...col10
row1 0.5 0.56 0.26 0.01
row2 2.45 3.25 0.45 10.2
.
.
row18262 0.9 0.32 1.11 2.5
row18263 N/A 0.25 N/A 4.5
or if anyone can suggest me a way to write the "Data" cell array into .xls file or .csv file, thats fine with me too.
My main objective is to somehow write the "Data" cell array to .xls for .csv file.
Thanks in advance.

回答(2 个)

Adam
Adam 2014-9-26
You could just set the missing values to NaN and have a 18263 * 10 matrix of doubles (or whatever size your real problem is) with the NaNs included. NaNs also have the advantage the you can plot data with them in (if you wish) and they behave sensibly by just not plotting rather than throwing an error or giving silly spikes as e.g. a 0 or -1 or some other invalid indicator value would.
I've never written data to an xls or csv file so I don't really know if you need it as doubles to do that or whether you can just write the cells as they are or with NaNs appended.
  4 个评论
Damith
Damith 2014-9-26
I need to read from RowID matrix from row 1 to 10 of col 2 and 3. And use those row numbers row1 and row 2 to read from col 5 of Gist144. This is working fine in MATLAB 2011 version but the error I am getting in 2014 version.
Hope I explained it well.
Adam
Adam 2014-9-26
You need to look at the class of your variables. It appears your variable has been changed to be a 'table' (doc table) in R2014a. Tables did not exist in R2011

请先登录,再进行评论。


Image Analyst
Image Analyst 2014-9-27
How about you just write each cell to it's own worksheet, so you'd have 10 worksheets in the workbook? It's best if you use ActiveX but you can use xlswrite() also - it's just slower.
for ws = 1 : 10
thisArray = Data{ws}; % Extract just this cell's contents.
sheetName = sprintf('Data %d', ws);
xlswrite(fullFileName, thisArray, sheetName, 'A1');
end

类别

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