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

6 次查看(过去 30 天)
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

采纳的回答

Walter Roberson
Walter Roberson 2015-7-29
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 个评论
David Stevens
David Stevens 2015-7-29
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

请先登录,再进行评论。

更多回答(0 个)

Community Treasure Hunt

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

Start Hunting!

Translated by