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

조회 수: 6 (최근 30일)
David Stevens
David Stevens 2015년 7월 28일
댓글: David Stevens 2015년 7월 29일
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개)

카테고리

Help CenterFile Exchange에서 Spreadsheets에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by