How to generate a .xls from a .mat using writexls

6 Ansichten (letzte 30 Tage)
David Stevens
David Stevens am 28 Jul. 2015
Kommentiert: David Stevens am 29 Jul. 2015
Dears, I am working on a MatLab database. I have a function able to produce a '.mat' listing the different variables presents in the database while respecting their inter-relations. Practically, this '.mat' will inform me about the countries presents in the database and the data (variables) linked with each of them (scenario, categories, entities, and sources). When I try to convert the '.mat' to an '.xls', I use the following code: "data=load('report.mat'); xlswrite('report.xls','report.mat')" I might sound stupid but this code just literally write 'report.mat' on a xcel sheet. If anyone might be able to provide me helps it could be great! Thanks.
David

Akzeptierte Antwort

Walter Roberson
Walter Roberson am 29 Jul. 2015
Possibly
data = load('report.mat');
fn = fieldnames(data);
report_contents = struct2cell(data);
data_to_write = vertcat(fn(:).', report_contents(:).');
xlswrite('report.xls', data_to_write)
This tries to create one column per variable name in the .mat file, using the name of the variable as the column header.
  1 Kommentar
David Stevens
David Stevens am 29 Jul. 2015
Hi Walter, thank you very much for your answer! it looks promising and helpful. Unfortunately it´s not really working, and I remain unclear why! I get a warning "ActiveX - invalid argument type or value", therefore I look to the class of the report typing "whos report" and obviously it´s a "struct". Then I don´t know why my output just keep on writing "report" on a excel sheet. Thank you for your help. David

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Community Treasure Hunt

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

Start Hunting!

Translated by