Effacer les filtres
Effacer les filtres

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

2 vues (au cours des 30 derniers jours)
David Stevens
David Stevens le 28 Juil 2015
Commenté : David Stevens le 29 Juil 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

Réponse acceptée

Walter Roberson
Walter Roberson le 29 Juil 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 commentaire
David Stevens
David Stevens le 29 Juil 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

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur MATLAB Report Generator dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by