Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Save a gui plot in a new file

Subject: Save a gui plot in a new file

From: Mara

Date: 6 Dec, 2012 01:30:14

Message: 1 of 4

Hello everyone,

I need your help.

I'm making a GUI with several push buttons and axes.
By clicking in a push button, appears a graph in the axes.

What I want to do is, by clicking in other push button, it saves the image in a new image file.

This is what I have:
--------------------------------------------------------------------------------------------------------------
function [ output_args ] = gera_imagem (grafico_i)

[ficheiro_nome3, directoria_nome3] = uiputfile('*.jpeg;*.tif;*.png;*.gif', 'Guardar a imagem:');
nome3 = fullfile(directoria_nome3,ficheiro_nome3);

saveas(grafico_i,nome3);

end
---------------------------------------------------------------------------------------------------------------

grafico_i is the plot that appears on GUI and that's what I want to save in the file named nome3..

What that saveas do is to save a bit of the GUI menu, not the graph...

How do I copy the graph that's created in the GUI to the new image file?

Can you help please?

Thanks a lot,
Mara

Subject: Save a gui plot in a new file

From: Kristin

Date: 7 Dec, 2012 13:59:08

Message: 2 of 4

"Mara " <mara.srosado@gmail.com> wrote in message <k9osf6$ohh$1@newscl01ah.mathworks.com>...
> Hello everyone,
>
> I need your help.
>
> I'm making a GUI with several push buttons and axes.
> By clicking in a push button, appears a graph in the axes.
>
> What I want to do is, by clicking in other push button, it saves the image in a new image file.
>
> This is what I have:
> --------------------------------------------------------------------------------------------------------------
> function [ output_args ] = gera_imagem (grafico_i)
>
> [ficheiro_nome3, directoria_nome3] = uiputfile('*.jpeg;*.tif;*.png;*.gif', 'Guardar a imagem:');
> nome3 = fullfile(directoria_nome3,ficheiro_nome3);
>
> saveas(grafico_i,nome3);
>
> end
> ---------------------------------------------------------------------------------------------------------------
>
> grafico_i is the plot that appears on GUI and that's what I want to save in the file named nome3..
>
> What that saveas do is to save a bit of the GUI menu, not the graph...
>
> How do I copy the graph that's created in the GUI to the new image file?
>
> Can you help please?
>
> Thanks a lot,
> Mara

When I've done this, I've made a new figure window and plot it in this new figure (or use COPYOBJ). Save this new figure window, then close it, as if nothing happened...

Or, you can grab the handles of the GUI-stuff (pushbuttons and whatnot) and hide them, then save the figure, then make them visible again.

set(uicontrol_handle, 'Visibility', 'off');

Subject: Save a gui plot in a new file

From: Richard Quist

Date: 7 Dec, 2012 17:54:08

Message: 3 of 4

"Mara " <mara.srosado@gmail.com> wrote in message <k9osf6$ohh$1@newscl01ah.mathworks.com>...
> Hello everyone,
>
> I need your help.
>
> I'm making a GUI with several push buttons and axes.
> By clicking in a push button, appears a graph in the axes.
>
> What I want to do is, by clicking in other push button, it saves the image in a new image file.
>
> This is what I have:
> --------------------------------------------------------------------------------------------------------------
> function [ output_args ] = gera_imagem (grafico_i)
>
> [ficheiro_nome3, directoria_nome3] = uiputfile('*.jpeg;*.tif;*.png;*.gif', 'Guardar a imagem:');
> nome3 = fullfile(directoria_nome3,ficheiro_nome3);
>
> saveas(grafico_i,nome3);
>
> end
> ---------------------------------------------------------------------------------------------------------------
>
> grafico_i is the plot that appears on GUI and that's what I want to save in the file named nome3..
>
> What that saveas do is to save a bit of the GUI menu, not the graph...
>
> How do I copy the graph that's created in the GUI to the new image file?
>
> Can you help please?
>
> Thanks a lot,
> Mara

The print command has a '-noui' option that might be useful for you. It will hide the the uicontrols before printing and then restore them after. I can't tell from your post whether grafico_i is the actual figure on not (print only works with figures), but if it is you can try calling
   print(grafico_i,nome3, '-noui');
instead of saveas

Hope that helps.

Subject: Save a gui plot in a new file

From: Mara

Date: 17 Dec, 2012 13:10:09

Message: 4 of 4

"Richard Quist" wrote in message <k9tag0$b0b$1@newscl01ah.mathworks.com>...
> "Mara " <mara.srosado@gmail.com> wrote in message <k9osf6$ohh$1@newscl01ah.mathworks.com>...
> > Hello everyone,
> >
> > I need your help.
> >
> > I'm making a GUI with several push buttons and axes.
> > By clicking in a push button, appears a graph in the axes.
> >
> > What I want to do is, by clicking in other push button, it saves the image in a new image file.
> >
> > This is what I have:
> > --------------------------------------------------------------------------------------------------------------
> > function [ output_args ] = gera_imagem (grafico_i)
> >
> > [ficheiro_nome3, directoria_nome3] = uiputfile('*.jpeg;*.tif;*.png;*.gif', 'Guardar a imagem:');
> > nome3 = fullfile(directoria_nome3,ficheiro_nome3);
> >
> > saveas(grafico_i,nome3);
> >
> > end
> > ---------------------------------------------------------------------------------------------------------------
> >
> > grafico_i is the plot that appears on GUI and that's what I want to save in the file named nome3..
> >
> > What that saveas do is to save a bit of the GUI menu, not the graph...
> >
> > How do I copy the graph that's created in the GUI to the new image file?
> >
> > Can you help please?
> >
> > Thanks a lot,
> > Mara
>
> The print command has a '-noui' option that might be useful for you. It will hide the the uicontrols before printing and then restore them after. I can't tell from your post whether grafico_i is the actual figure on not (print only works with figures), but if it is you can try calling
> print(grafico_i,nome3, '-noui');
> instead of saveas
>
> Hope that helps.




Thanks for your answer!

I solved the problem making a figure..then the window to save appears automatically (I used saveas function but it also could be done using print) and as the user saves the image, the figure closes. That's not perfect, but result. I didn't find a way so I could save the image without opening it outside of the GUI..

Even I did what you told me, I would have to open a figure to save the plot..so I prefer the way I did, which doesn't envolve hidding the gui buttons...

Again, thanks a lot,

Mara

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us