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

14 visualizaciones (últimos 30 días)
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.

Respuestas (1)

Sai Teja G
Sai Teja G el 22 de Nov. de 2023
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 comentarios
Sai Teja G
Sai Teja G el 22 de Nov. de 2023
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 el 22 de Nov. de 2023
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")

Iniciar sesión para comentar.

Categorías

Más información sobre Printing and Saving en Help Center y File Exchange.

Productos


Versión

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by