Plotting on .fig file (in new window if possible)

Hello,
I am trying to open a figure and plot additional data on it. The figure was given to me as a .fig file so I do not have the data to recreate it.
To open the file, I am using the following code:
fig = openfig('filename');
However that opens it in the script tab and not as a new figure window. How can I open it in a new figure window like all my other plots?
Once I have that opened (regardless of in new window or not), how do I plot on it?
I am trying
openfig('filename')
hold on
plot(x,y)
But that doesn't seem to be working.
Any help is greatly appreciated.
Thanks!

4 comentarios

Turlough Hughes
Turlough Hughes el 9 de Oct. de 2019
Can you upload the .fig file?
JD
JD el 10 de Oct. de 2019
Image attached
image.jpeg
Stephan
Stephan el 10 de Oct. de 2019
Upload the file means to attach the .fig file i guess- not a picture of it.
JD
JD el 10 de Oct. de 2019
My bad. Attached is the .fig file

Iniciar sesión para comentar.

 Respuesta aceptada

Walter Roberson
Walter Roberson el 9 de Oct. de 2019
Figures are container objects that cannot be directly drawn to. You can only plot() into axes. Axes are contained inside figures or inside uipanels (or a small number of other container types.)
In order to draw, you will need to either select an existing axes or else create a new axes inside the figure.
%get the figure
fig = openfig('filename');
%pull out the right axes
fig_axes = findobj(fig, 'type', 'axes');
selected_axes_idx = 2; %set as appropriate for your purpose
ax = fig_axes(selected_axes_idx);
%do the additional drawing
hold(ax, 'on');
x = linspace(-2*pi,2*pi);
y1 = cos(x);
plot(ax, x, y1, 'color', 'b');
hold(ax, 'off');

5 comentarios

JD
JD el 9 de Oct. de 2019
Editada: JD el 9 de Oct. de 2019
Hi Walter,
What does selected_axes_idx mean? Any number larger than 1 gives me the error "Index exceeds the number of array elements (1)"
Attached is my .fig file and the point I am trying to plot. On a normal figure, this would be fairly simple, but I'm having trouble plotting on a .fig file.
fig = openfig('enginemap.fig');
fig_axes = findobj(fig, 'type', 'axes');
selected_axes_idx = 1;
ax = fig_axes(selected_axes_idx);
hold(ax, 'on');
plot(1719.6,270.2, 'x r')
hold(ax, 'off');
Your marker just was not very visible.
%get the figure
filename = 'enginemap.fig';
fig = openfig(filename);
%pull out the right axes
ax = gca(fig);
%do the additional drawing
hold(ax, 'on')
plot(1719.6,270.2, 'x r', 'MarkerSize', 40);
hold(ax, 'off');
JD
JD el 10 de Oct. de 2019
Hi Walter,
That still didn't work. I am attaching the .fig file if you would like to test it
Walter Roberson
Walter Roberson el 10 de Oct. de 2019
I tested with the .fig you posted earlier, and it worked fine for me.
Which MATLAB release are you using?
JD
JD el 10 de Oct. de 2019
Editada: JD el 10 de Oct. de 2019
Hi Walter,
Ignore my previous comment about it not working. I had many other figures in my code and it was plotting it on those instead of the one I wanted to plot it on. So I created an empty script just for this section of the code.
Thanks so much for your help!

Iniciar sesión para comentar.

Más respuestas (1)

Ankit
Ankit el 9 de Oct. de 2019
Here is an example:
close all;
MySavedPlot = open('MySavedPlot.fig');
figure(MySavedPlot)
hold on
x = linspace(-2*pi,2*pi);
y1 = cos(x);
plot(x,y1,'color','b')

Categorías

Más información sobre Creating, Deleting, and Querying Graphics Objects en Centro de ayuda y File Exchange.

Productos

Preguntada:

JD
el 9 de Oct. de 2019

Editada:

JD
el 10 de Oct. de 2019

Community Treasure Hunt

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

Start Hunting!

Translated by