xlswrite dropping strings

1 visualizzazione (ultimi 30 giorni)
Trader
Trader il 3 Apr 2012
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!

Risposte (2)

Kye Taylor
Kye Taylor il 3 Apr 2012
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 Commenti
Trader
Trader il 4 Apr 2012
I see how that would work however the situation I'm in is just a little more complex...
the structure metric has several arrays, so how would you write the following?
metrics.position(1) = {'waiting'};
metrics.action(1) = {'short'};
metrics.name(1) = {'abc'};
results.full_data(end+1,:) = {metrics.position(1) metrics.action(1) metrics.name(1)}
Thank you for your help, I really appreciate it!
Kye Taylor
Kye Taylor il 4 Apr 2012
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];

Accedi per commentare.


Image Analyst
Image Analyst il 4 Apr 2012
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.

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by