How do I keep all plots open?

64 ビュー (過去 30 日間)
Hao Sun
Hao Sun 2020 年 3 月 23 日
回答済み: Avni Agrawal 2025 年 2 月 19 日 8:25
How do I keep plots open (even when function or code finishes) and have new plots just create a new plot (not on same axis or anything)
Also how to save multiple plots? e.g. have a function that everytime is run automatically saves the plot to some folder or something
  3 件のコメント
Sindar
Sindar 2020 年 3 月 24 日
Also, "print" saves figures
"print(filename,formattype) saves the current figure to a file using the specified file format, such as print('BarPlot','-dpng'). If the file name does not include an extension, then print appends the appropriate one."
Samayochita
Samayochita 2025 年 2 月 5 日 8:49
編集済み: Samayochita 2025 年 2 月 5 日 8:50
Using saveas :
figure;
plot(x, y);
saveas(gcf, 'Plot1.png'); % Saves the current figure

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

回答 (1 件)

Avni Agrawal
Avni Agrawal 2025 年 2 月 19 日 8:25
I understand that you are trying to keep plots open, create new plots, and save them in MATLAB.
To ensure each plot opens in a new window:
% Example: Plotting data
figure; % Opens a new figure window
plot(x, y); % Plot your data
You can save plots using saveas or exportgraphics:
1. Using saveas: Saves the figure in specified format (e.g., PNG, JPEG).
% Example: Save plot as PNG
figure;
plot(x, y);
folderPath = 'C:\Your\Path'; % Specify the folder path
if ~exist(folderPath, 'dir')
mkdir(folderPath); % Create folder if it doesn't exist
end
filename = sprintf('plot_%d.png', plotNumber);
saveas(gcf, fullfile(folderPath, filename));
2. Using exportgraphics: Offers more control over file format and resolution.
% Example: Save plot with high resolution
figure;
plot(x, y);
folderPath = 'C:\Your\Path';
if ~exist(folderPath, 'dir')
mkdir(folderPath);
end
filename = sprintf('plot_%d.png', plotNumber);
exportgraphics(gcf, fullfile(folderPath, filename), 'Resolution', 300);
By using these methods, you can keep plots open, create new ones, and save them automatically in a specified directory.
I hope this helps!

カテゴリ

Help Center および File ExchangePrinting and Saving についてさらに検索

製品


リリース

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by