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

5 views (last 30 days)
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

Accepted Answer

Walter Roberson
Walter Roberson on 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 Comment
David Stevens
David Stevens on 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

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!