Create Figure Without Displaying it (2024)

1.172 Ansichten (letzte 30 Tage)

Ältere Kommentare anzeigen

John F am 11 Jul. 2012

  • Verknüpfen

    Direkter Link zu dieser Frage

    https://de.mathworks.com/matlabcentral/answers/43326-create-figure-without-displaying-it

  • Verknüpfen

    Direkter Link zu dieser Frage

    https://de.mathworks.com/matlabcentral/answers/43326-create-figure-without-displaying-it

Beantwortet: Walter Roberson am 14 Mai 2023

Hi,

I'd like to create a figure and save it in the background without displaying it.

I've heard of setting the "visibility" setting to "off", but the figure window still pops up.

I'd rather just have the figure be created and saved in its specified folder without having to see it.

Any way to do this?

Thanks,

JF

0 Kommentare

-2 ältere Kommentare anzeigen-2 ältere Kommentare ausblenden

Melden Sie sich an, um zu kommentieren.

Melden Sie sich an, um diese Frage zu beantworten.

Antworten (5)

Thomas am 11 Jul. 2012

  • Verknüpfen

    Direkter Link zu dieser Antwort

    https://de.mathworks.com/matlabcentral/answers/43326-create-figure-without-displaying-it#answer_53210

  • Verknüpfen

    Direkter Link zu dieser Antwort

    https://de.mathworks.com/matlabcentral/answers/43326-create-figure-without-displaying-it#answer_53210

Bearbeitet: Thomas am 11 Jul. 2012

In MATLAB Online öffnen

Something like this?

a=1:4;

f = figure('visible','off');

plot(a)

saveas(f,'newout','fig')

Now to reopen the figure

% to open the figure

openfig('newout.fig','new','visible')

4 Kommentare

2 ältere Kommentare anzeigen2 ältere Kommentare ausblenden

MA-Winlab am 24 Mär. 2019

Direkter Link zu diesem Kommentar

https://de.mathworks.com/matlabcentral/answers/43326-create-figure-without-displaying-it#comment_684913

  • Verknüpfen

    Direkter Link zu diesem Kommentar

    https://de.mathworks.com/matlabcentral/answers/43326-create-figure-without-displaying-it#comment_684913

Why I am not able to juts click on the saved figure to open it? I was able to view the figure only by using openfig!

Walter Roberson am 24 Mär. 2019

Direkter Link zu diesem Kommentar

https://de.mathworks.com/matlabcentral/answers/43326-create-figure-without-displaying-it#comment_684916

  • Verknüpfen

    Direkter Link zu diesem Kommentar

    https://de.mathworks.com/matlabcentral/answers/43326-create-figure-without-displaying-it#comment_684916

double-click on a .fig will open it.

Note: .fig that are created by GUIDE will not be able to run their GUI if you open them this way. To launch a GUIDE GUI, you need to execute the .m file.

MA-Winlab am 24 Mär. 2019

Direkter Link zu diesem Kommentar

https://de.mathworks.com/matlabcentral/answers/43326-create-figure-without-displaying-it#comment_685031

  • Verknüpfen

    Direkter Link zu diesem Kommentar

    https://de.mathworks.com/matlabcentral/answers/43326-create-figure-without-displaying-it#comment_685031

I am double clicking on the .fig files but they do not open. Hence I am using the line provided by @Thomas to save the figures!

Derek Rose am 13 Aug. 2020

Direkter Link zu diesem Kommentar

https://de.mathworks.com/matlabcentral/answers/43326-create-figure-without-displaying-it#comment_971760

  • Verknüpfen

    Direkter Link zu diesem Kommentar

    https://de.mathworks.com/matlabcentral/answers/43326-create-figure-without-displaying-it#comment_971760

Bearbeitet: Derek Rose am 13 Aug. 2020

In MATLAB Online öffnen

It's because the figure is still set to 'visible', 'off' when you save it. If you want it to be visible when you reopen it in MATLAB, then you need to use

a=1:4;

f = figure('visible','off');

plot(a)

%do all other plotting to the figure here before making visible, saving, and closing

set(f, 'visible', 'on');

saveas(f, 'newout', 'fig');

close(f)

I know this seems redundent becuase this will cause it to flash on the screen for an instant while saving, but this is way better in the instance your function is accessing the figure, while visible, over and over again to add new data.

Melden Sie sich an, um zu kommentieren.

Luffy am 11 Jul. 2012

  • Verknüpfen

    Direkter Link zu dieser Antwort

    https://de.mathworks.com/matlabcentral/answers/43326-create-figure-without-displaying-it#answer_53209

  • Verknüpfen

    Direkter Link zu dieser Antwort

    https://de.mathworks.com/matlabcentral/answers/43326-create-figure-without-displaying-it#answer_53209

Bearbeitet: Walter Roberson am 31 Okt. 2016

In MATLAB Online öffnen

If h = figure;set(h, 'Visible', 'off');

% do ur plotting here

saveas(h,'figure.png');

You will not see a figure popping up,but you can see h in workspace

3 Kommentare

1 älteren Kommentar anzeigen1 älteren Kommentar ausblenden

Blanca Larraga am 4 Jun. 2018

Direkter Link zu diesem Kommentar

https://de.mathworks.com/matlabcentral/answers/43326-create-figure-without-displaying-it#comment_574880

  • Verknüpfen

    Direkter Link zu diesem Kommentar

    https://de.mathworks.com/matlabcentral/answers/43326-create-figure-without-displaying-it#comment_574880

I still get the figure popping up. I have some subplots within my figure; could this be the reason why? How could I solve it?

Aaron Kaw am 9 Mär. 2022

Direkter Link zu diesem Kommentar

https://de.mathworks.com/matlabcentral/answers/43326-create-figure-without-displaying-it#comment_2028944

  • Verknüpfen

    Direkter Link zu diesem Kommentar

    https://de.mathworks.com/matlabcentral/answers/43326-create-figure-without-displaying-it#comment_2028944

I have the same questions, except I'm using tiledlayout.

Walter Roberson am 9 Mär. 2022

Direkter Link zu diesem Kommentar

https://de.mathworks.com/matlabcentral/answers/43326-create-figure-without-displaying-it#comment_2029054

  • Verknüpfen

    Direkter Link zu diesem Kommentar

    https://de.mathworks.com/matlabcentral/answers/43326-create-figure-without-displaying-it#comment_2029054

If you make changes to a figure that is not visible, then depending exactly what you do, the updates might not be completed until you let the figure render by making it visible. For example xlim auto will not update until the axes is made visible which requires that the figure be visible. Therefore making a figure invisible and updating it and saving it without making it visible can result in it not saving updated plots. So you probably want to make the figure visible before saving anyways.

If you do save a figure that is not visible then the visible state will be saved and opening the file will not show you anything unless you asked to override visibility when you open.

Melden Sie sich an, um zu kommentieren.

cmmv am 13 Jun. 2016

  • Verknüpfen

    Direkter Link zu dieser Antwort

    https://de.mathworks.com/matlabcentral/answers/43326-create-figure-without-displaying-it#answer_225292

  • Verknüpfen

    Direkter Link zu dieser Antwort

    https://de.mathworks.com/matlabcentral/answers/43326-create-figure-without-displaying-it#answer_225292

Bearbeitet: cmmv am 13 Jun. 2016

In MATLAB Online öffnen

What if we create mutiple figure handles first. Then, the current axis (gca) corresponds to the final handle created. Currently, i set the gca using figure(handle);

How then, do we maintain the visibility setting 'off' if needing to call the handles in any order for plotting.

EG:

h1 = figure('doublebuffer','off','Visible','Off');

h2 = figure('doublebuffer','off','Visible','Off'); %gca is now here

set(h1,'Units','pixels','Position',[1 1 850 375]);

figure(h1); %<--- this continues to make h1 "visible"

subplot(1,2,1);

plot(time, data);

2 Kommentare

Keine anzeigenKeine ausblenden

Bart Doekemeijer am 31 Okt. 2016

Direkter Link zu diesem Kommentar

https://de.mathworks.com/matlabcentral/answers/43326-create-figure-without-displaying-it#comment_402944

  • Verknüpfen

    Direkter Link zu diesem Kommentar

    https://de.mathworks.com/matlabcentral/answers/43326-create-figure-without-displaying-it#comment_402944

In MATLAB Online öffnen

You will want to do:

set(0,'CurrentFigure',h1);

Aastav Sen am 23 Nov. 2020

Direkter Link zu diesem Kommentar

https://de.mathworks.com/matlabcentral/answers/43326-create-figure-without-displaying-it#comment_1154228

  • Verknüpfen

    Direkter Link zu diesem Kommentar

    https://de.mathworks.com/matlabcentral/answers/43326-create-figure-without-displaying-it#comment_1154228

In MATLAB Online öffnen

Awesome!

This works for me (adding data to a plot within a loop without having Matlab steal the focus so I can work on other things at the same time)! So in a nutshell:

Call before your loop:

fg = figure(1)

But during your loop when you want to update the contents of a figure this requires you to 'grab' the figure and set it to your current figure handle = 'gcf'. You do this using:

set(0,'CurrentFigure',fg);

Note: that if you instead used in you loop:

fg = figure(1)

This would set the 'gcf' to our figure (what we want), but, would also steal the focus (what we don't want)!

Hope this helps.

Melden Sie sich an, um zu kommentieren.

Walter Roberson am 14 Mai 2023

  • Verknüpfen

    Direkter Link zu dieser Antwort

    https://de.mathworks.com/matlabcentral/answers/43326-create-figure-without-displaying-it#answer_1234809

  • Verknüpfen

    Direkter Link zu dieser Antwort

    https://de.mathworks.com/matlabcentral/answers/43326-create-figure-without-displaying-it#answer_1234809

I'd like to create a figure and save it in the background without displaying it.

In MATLAB, creating a figure always makes the figure visible, even if 'visible', 'off' is set. Having 'visible', 'off' at the time of figure creating still makes the figure visible and then immediately turns off visibility -- but it might (or might not) monetarily flash on the screen.

MATLAB's internal graphics system is (for whatever reason) only set up to finalize the values of some internal positions at the time that a figure is made visible, so MATLAB's graphic system strictly needs this.

Furthermore, some changes (especially related to positions and automatic choice of axes boundaries and associated ticks and labels) are postponed when the graphics object is not set to 'visible', 'on', so if you have set a figure to 'visible', 'off' and you make graphics changes, it may be necessary to set the visibility on before you can properly capture the screen or query the properties.

Also, the way to determine how much space some text would take if it were made visible, or the way to automatically wrap text, requires that the associated component be visible. If you are trying to auto-size components (creating an attractive screen layout based upon how much space is needed) then you end up having to create a prototype of the object, having the object flash on the screen, read out its properties, and then deleting the prototype object. (At least for traditional figures; there are newer text-wrapping facilities that perhaps do not need this.)

It is not ideal, but it is what we have to work with.

0 Kommentare

-2 ältere Kommentare anzeigen-2 ältere Kommentare ausblenden

Melden Sie sich an, um zu kommentieren.

Kc Nkurumeh am 14 Mai 2023

  • Verknüpfen

    Direkter Link zu dieser Antwort

    https://de.mathworks.com/matlabcentral/answers/43326-create-figure-without-displaying-it#answer_1234794

  • Verknüpfen

    Direkter Link zu dieser Antwort

    https://de.mathworks.com/matlabcentral/answers/43326-create-figure-without-displaying-it#answer_1234794

You can keep the figures docked. For me this stops the constant focus stealing, however, some display commands don't work correctly when the figure is docked. For example rotating text.

set(0,'DefaultFigureWindowStyle','normal')

0 Kommentare

-2 ältere Kommentare anzeigen-2 ältere Kommentare ausblenden

Melden Sie sich an, um zu kommentieren.

Melden Sie sich an, um diese Frage zu beantworten.

Siehe auch

Kategorien

MATLABGraphicsGraphics ObjectsGraphics Object Properties

Mehr zu Graphics Object Properties finden Sie in Help Center und File Exchange

Tags

  • figure
  • visible
  • visibility
  • background
  • image
  • create

Community Treasure Hunt

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

Start Hunting!

Es ist ein Fehler aufgetreten

Da Änderungen an der Seite vorgenommen wurden, kann diese Aktion nicht abgeschlossen werden. Laden Sie die Seite neu, um sie im aktualisierten Zustand anzuzeigen.


Translated by Create Figure Without Displaying it (16)

Create Figure Without Displaying it (17)

Website auswählen

Wählen Sie eine Website aus, um übersetzte Inhalte (sofern verfügbar) sowie lokale Veranstaltungen und Angebote anzuzeigen. Auf der Grundlage Ihres Standorts empfehlen wir Ihnen die folgende Auswahl: .

Sie können auch eine Website aus der folgenden Liste auswählen:

Amerika

  • América Latina (Español)
  • Canada (English)
  • United States (English)

Europa

  • Belgium (English)
  • Denmark (English)
  • Deutschland (Deutsch)
  • España (Español)
  • Finland (English)
  • France (Français)
  • Ireland (English)
  • Italia (Italiano)
  • Luxembourg (English)
  • Netherlands (English)
  • Norway (English)
  • Österreich (Deutsch)
  • Portugal (English)
  • Sweden (English)
  • Switzerland
    • Deutsch
    • English
    • Français
  • United Kingdom(English)

Asien-Pazifik

Kontakt zu Ihrer lokalen Niederlassung

Create Figure Without Displaying it (2024)

References

Top Articles
Latest Posts
Article information

Author: Catherine Tremblay

Last Updated:

Views: 5832

Rating: 4.7 / 5 (47 voted)

Reviews: 86% of readers found this page helpful

Author information

Name: Catherine Tremblay

Birthday: 1999-09-23

Address: Suite 461 73643 Sherril Loaf, Dickinsonland, AZ 47941-2379

Phone: +2678139151039

Job: International Administration Supervisor

Hobby: Dowsing, Snowboarding, Rowing, Beekeeping, Calligraphy, Shooting, Air sports

Introduction: My name is Catherine Tremblay, I am a precious, perfect, tasty, enthusiastic, inexpensive, vast, kind person who loves writing and wants to share my knowledge and understanding with you.