Copy the curve in the Axes of a Figure to the Axes of a GUI

4 visualizzazioni (ultimi 30 giorni)
I have a figure (simple sine curve). Figure 1. And I have an Axis in a GUI (guide), with the tag axes1.
I want to copy this cruve from Figure 1 to the GUI.
I have tried the following on a button in the guide code:
FigAxes = findobj('Parent',figure(1),'Type','axes');
axes(handles.axes1);
plot(FigAxes);
I also tried to use findobj for the axes in the GUI (guide) and then use copyobj. and i dont know how.
FigAxes = findobj('Parent',figure(1),'Type','axes');
GUIAxes = findobj(); %code to find axes1 in guide;
copyobj(FigAxes,GUIAxes);
Nothing worked. Any suggestions?
  13 Commenti
Sami Tuffaha
Sami Tuffaha il 15 Ott 2018
Hi Adam, thank you alot! Thank you Dennis and Kevin for your help too.
the following code worked:
hLine = findobj( figure(1), 'Type', 'line' );
copyobj( hLine, handles.axes1 );
How can I accept your reply as the answer of my question

Accedi per commentare.

Risposta accettata

Adam
Adam il 15 Ott 2018
If you have the handle of figure 1 as hFig then
hLine = findobj( hFig.CurrentAxes, 'Type', 'line' )
or
hLine = findobj( hFig, 'Type', 'line' )
would work, but again a lot depends on the figure and the axes you are taking these from - e.g. if you have multiple axes in your figure or multiple plots in your axes. In the latter case that may be what you want as it would copy all the line plots to your GUI.
Those two options would be equivalent if you just have 1 axes containing 1 line.
It is always useful to check the documentation though. This syntax of findobj is shown in
doc findobj
Where possible though it is always best to store handles when you create figure or axes or plot data though than have to find it afterwards using findobj
  1 Commento
Sami Tuffaha
Sami Tuffaha il 15 Ott 2018
the following code worked:
hLine = findobj( figure(1), 'Type', 'line' );
copyobj( hLine, handles.axes1 );

Accedi per commentare.

Più risposte (2)

Kevin Chng
Kevin Chng il 14 Ott 2018
Hi,
Refer to my code, you are almost there.
a=figure;
plot([0 1],[0 1])
FigAxes = findobj('Parent',a,'Type','axes');
b= figure;
copyobj(FigAxes,b);
Kindly accept my answer if it helps you.
  3 Commenti
Kevin Chng
Kevin Chng il 15 Ott 2018
Modificato: Kevin Chng il 15 Ott 2018
At this moment, i don't have answer for it. However, there is alternative solution which is save your axes as image and display them in your Guide axes. But i'm afraid this is not what you want.
Sami Tuffaha
Sami Tuffaha il 15 Ott 2018
displaying the cruve as an image in my guide axes will not solve my problem unfortunately :(

Accedi per commentare.


Bruno Luong
Bruno Luong il 15 Ott 2018
Modificato: Bruno Luong il 15 Ott 2018
% Fake plot
axesrc = axes('Parent',figure(1));
plot(axesrc,sin(linspace(0,4*pi)));
axedest = axes('Parent',figure(2)); % Replace this with your GUI axes
copyobj(get(axesrc,'Children'),axedest)

Categorie

Scopri di più su Creating, Deleting, and Querying Graphics Objects in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by