xlswrite dropping strings
1 次查看(过去 30 天)
显示 更早的评论
I'm trying to write to an xls file and for the most part it's working, however it is not writing my strings.
result.xls_full_data: {401x17 cell}
xlswrite(file_out, results.xls_full_data, 1, '2');
what am I missing here?
Thanks!
0 个评论
回答(2 个)
Kye Taylor
2012-4-3
It's hard to tell without more detail on the contents of result.xls_full_data. However, if your strings are nested in a cell inside a cell, xlswrite will overlook them. To be precise, consider the two different cell arrays below
X = [num2cell(rand(4,7)),{'red';'blue';'green';'yellow'}]
and
Y = [num2cell(rand(4,7)),{{'red'};{'blue'};{'green'};{'yellow'}}]
The difference between X and Y is that the cells containing strings in X are cells whose contents are strings, whereas the cells containing strings in Y are actually cells whose contents are cells whose contents are strings. (cell of cell of string)
If you attempt the following commands, you'll see that the strings in Y are not written to the mySecond.xls file.
xlswrite('myFirst.xls',X,1,'2');
xlswrite('mySecond.xls',Y,1,'2');
Perhaps this explains the behavior you're observing?
4 个评论
Kye Taylor
2012-4-4
No problem!
There's two ways we can proceed, but it depends on your answer to the following: Do you have all of metrics.position, metrics.action, and metrics.name before creating results.full_data?
Other questions that could help if answered include:
1.) True or False? The output of class(results.full_data) is cell.
2.) What is the size of metrics.position, metrics.action, and metrics.name?
3.) How big do you expect results.full_data to be when it's all over? I.e. how many cells will you write to in the excel file?
In the meantime, if metrics.position, metrics.action, and metrics.name are n-by-1 cell arrays, then you may want to try
results.full_data = [metrics.position,metrics.action,metrics.name];
Image Analyst
2012-4-4
In
xlswrite(file_out, results.xls_full_data, 1, '2');
You're writing out to sheet "1" (which is fine), but cell "2" which I don't think is. Give it an upper left cell designation, like "A1" or "c23" or something like that.
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!