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:
.fig not saved properly using "saveas"

Subject: .fig not saved properly using "saveas"

From: Nathan

Date: 5 Apr, 2013 20:30:13

Message: 1 of 5

In the following section of code, I am attempting to save a plot (a figure within a custom GUI) as a ".fig" file. The file seems to save properly, but when I open the ".fig" file in MATLAB, it only appears as graphic. That is, the image is pixelated and the plot's data is not accessible using MATLAB's figure tools. For example, the Data Cursor selects pixel values rather than data points along the curve.

The applicable code section:

saveFolder = uigetdir(savePath);
F=getframe(handles.axes1); %select axes in GUI
figure(); %new figure
fileTitle = saveFileName; %filename
image(F.cdata); %show selected axes in new figure
saveas(gcf, fullfile(saveFolder,fileTitle),'fig'); %save figure
close(gcf); %and close it

Subject: .fig not saved properly using "saveas"

From: someone

Date: 5 Apr, 2013 21:25:06

Message: 2 of 5

"Nathan " <nathan.hamilton@uah.edu> wrote in message <kjnc8k$48b$1@newscl01ah.mathworks.com>...
> In the following section of code, I am attempting to save a plot (a figure within a custom GUI) as a ".fig" file. The file seems to save properly, but when I open the ".fig" file in MATLAB, it only appears as graphic. That is, the image is pixelated and the plot's data is not accessible using MATLAB's figure tools. For example, the Data Cursor selects pixel values rather than data points along the curve.

I may be wrong, but I believe that is the normal and intended behavior of the SAVEAS command.
Try HGSAVE instead, that may be what you are looking for.

doc hgsave
doc hgload

>
> The applicable code section:
>
> saveFolder = uigetdir(savePath);
> F=getframe(handles.axes1); %select axes in GUI
> figure(); %new figure
> fileTitle = saveFileName; %filename
> image(F.cdata); %show selected axes in new figure
> saveas(gcf, fullfile(saveFolder,fileTitle),'fig'); %save figure
> close(gcf); %and close it

Subject: .fig not saved properly using "saveas"

From: Nathan

Date: 5 Apr, 2013 22:08:06

Message: 3 of 5

> I may be wrong, but I believe that is the normal and intended behavior of the SAVEAS command.

Take the following code as an example:

x = 1:10;
y = x.^2;
plot(x,y)

After running this in the terminal and saving the resulting plot as a ".fig" file, the ".fig" file can be opened and its data points viewed using the Data Cursor. The plots's axes are also setup correctly. Furthermore, the plot can be resized dynamically.

I would like to be able to save a figure the same way using my GUI. I thought that "saveas" permitted such functionality. However, when I save the plot created in the GUI and open the figure in MATLAB, the .fig has none of the functionality present in the example above.

I've attempted to use "hgsave" with no better luck.

Subject: .fig not saved properly using "saveas"

From: Richard Quist

Date: 9 Apr, 2013 18:05:07

Message: 4 of 5

"Nathan " <nathan.hamilton@uah.edu> wrote in message <kjnc8k$48b$1@newscl01ah.mathworks.com>...
> In the following section of code, I am attempting to save a plot (a figure within a custom GUI) as a ".fig" file. The file seems to save properly, but when I open the ".fig" file in MATLAB, it only appears as graphic. That is, the image is pixelated and the plot's data is not accessible using MATLAB's figure tools. For example, the Data Cursor selects pixel values rather than data points along the curve.
>
> The applicable code section:
>
> saveFolder = uigetdir(savePath);
> F=getframe(handles.axes1); %select axes in GUI
> figure(); %new figure
> fileTitle = saveFileName; %filename
> image(F.cdata); %show selected axes in new figure
> saveas(gcf, fullfile(saveFolder,fileTitle),'fig'); %save figure
> close(gcf); %and close it

Nathan,
When you are calling saveas above, the figure you're saving only contains the image that you retrieved by calling getframe.

I think what you want to do is call saveas with the original figure (whatever figure handles.axes1 belongs to).

If you want to save JUST the axes that is referenced by handles.axes1, you'll need to copy that axes to a new figure and then save that figure.
  newfig = figure;
  copyobj(handles.axes1, newfig);
  saveas(newfig, ....)

You may need to tweak the code to get the size/layout you want, but hopefully this will be of some help.

Subject: .fig not saved properly using "saveas"

From: Nathan

Date: 10 Apr, 2013 05:49:14

Message: 5 of 5

"Richard Quist" wrote in message <kk1l8j$d4o$1@newscl01ah.mathworks.com>...

> If you want to save JUST the axes that is referenced by handles.axes1, you'll need to copy that axes to a new figure and then save that figure.
> newfig = figure;
> copyobj(handles.axes1, newfig);
> saveas(newfig, ....)
>

Thanks! That does exactly what I wanted.

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