フィルターのクリア

How to convert MATLAB plots to xls (Excel) sheets ?

4 ビュー (過去 30 日間)
Adnan Hayat
Adnan Hayat 2020 年 8 月 21 日
コメント済み: Adnan Hayat 2020 年 8 月 24 日
I have almost ten to fifteen MATLAB figures which I've got by running a MATLAB code. The code takes hours to plot a figure. My professor has now asked me to make .xls (Excel) sheets from the data associated with these figures. Although, I know how to do it and that is by using the "xlswrite" command, but, really ?, I have to run the code for hours again? Can anybody recoomend me an easy way using which I could get data files directly from the MATLAB figures ?

採用された回答

Arthur Roué
Arthur Roué 2020 年 8 月 21 日
編集済み: Arthur Roué 2020 年 8 月 21 日
You can access data of a plot with the line handle. For instance :
% Current figure handle (or use openfig if you saved the figure in a FIG-File)
hFigure = gcf;
% Find line handle
hLines = findobj(gcf, 'Type', 'Line')
% Here are your data
hLines.XData
hLines.YData
In this example, I assume you have only one line in each plot.
Since R2019a, prefer writetable, writematrix, or writecell instead of xlswrite
  11 件のコメント
Arthur Roué
Arthur Roué 2020 年 8 月 24 日
Here you go
% Current figure handle (or use openfig if you saved the figure in a FIG-File)
hFigure = gcf;
% Find lines handles
vhLines = findobj(gcf, 'Type', 'Line');
% X data, I assume it's the same for all lines (otherwise use interp1)
vX = vhLines(1).XData;
% All Y data
mY = vertcat(vhLines.YData)';
% All names
cNames = {vhLines.DisplayName};
% Cell to export
cToExport = [
't [s]', cNames; % Headers
num2cell([vX', mY])];
% Write into file
xlswrite('YourWorkbook.xlsx', cToExport, 'YourSheetName')
Adnan Hayat
Adnan Hayat 2020 年 8 月 24 日
Dear Arthur, Thanks alot. It worked :)

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeSpreadsheets についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by