For Live Editor: How to save figures in live editor in window state maximed or fullscreen?

조회 수: 12 (최근 30일)
Hi, i am wondering can we save matlab figures using figure properties in live script.
F= figure;
F.WindowState="Maximized";
export_fig(F,"some name","-png");
The above code works perfectly in .mat format but not in .mlx format. In .mlx format, i have to manullay maximize the screen and than use the save command, otherwise it will just save the small figure created in live editor window.
Is there a workaround rather than converting the script to .mat format or am i missing something.

답변 (1개)

Sai Teja G
Sai Teja G 2023년 11월 22일
Hi Arjun,
I understand that you want to save the figures while working in Live Script Editor.
Several potential solutions exist to address this issue, and you may wish to experiment with both to determine which one effectively resolves your problem.
One method involves utilizing the 'maximize' function in conjunction with the 'pause' function to ensure that the figure fully renders within the Live Script Editor. Please refer to the following code as an example of how to implement this approach.
% Create a new figure
F = figure;
% Set the figure to not display inline in Live Script
set(F, 'WindowStyle', 'normal');
% Maximize the figure window
F.WindowState = 'maximized';
% Pause for a moment to ensure the window state is updated
pause(1);
% Export the figure using the 'export_fig' function
export_fig(F, 'some_name', '-png');
% Close the figure if not needed anymore
close(F);
Another method to save figures in MATLAB is by using the built-in functions 'exportgraphics' or 'saveas'. These functions allow you to save your figures programmatically with more control over the output format and appearance. Below is example of how to use these functions:
% Using 'saveas'
saveas(F, 'some_name.png');
% Or using 'exportgraphics' for better quality
exportgraphics(F, 'some_name.png');
Hope it helps!
  댓글 수: 3
Sai Teja G
Sai Teja G 2023년 11월 22일
Hi, both the workarounds are working fine for me. Can you tell me your exact workflow so that I can reproduce the error you are facing.
arjun luther
arjun luther 2023년 11월 22일
Hi , i tried this example
% Create a new figure
F = figure;
% Set the figure to not display inline in Live Script
set(F, 'WindowStyle', 'normal');
% some plot
bar(75)
% Maximize the figure window
F.WindowState = 'maximized';
% Pause for a moment to ensure the window state is updated
pause(5);
% Export the figure using the 'export_fig' function
exportgraphics(F, 'some_name.png');
% Close the figure if not needed anymore
% close(F);
and i use this command after maximzing the figure manually to save it, the results are attached as attachments.
export_fig("another fig","-png")

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Printing and Saving에 대해 자세히 알아보기

제품


릴리스

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by