Add lines to plot

12 visualizaciones (últimos 30 días)
Max Müller
Max Müller el 7 de Ag. de 2014
Editada: Max Müller el 8 de Ag. de 2014
Hey Guys, I have created a func. which plots me some Data. Inside my func. I use this code
Plot = figure
set(Plot, 'Position', [306,200, 1610,1085]);
set(Plot,'name','Plot','numbertitle','off');
my Question is now: how can I add more Plot lines without opening a new figure ?

Respuesta aceptada

Max Müller
Max Müller el 7 de Ag. de 2014
Editada: Max Müller el 8 de Ag. de 2014
if isempty( findobj('Tag','Plot')) == 1
Plot = figure
set(Plot, 'Position', [306,200, 1610,1085]);
set(Plot,'name','Plot','Tag','Plot','numbertitle','off');
else
MakeFigureCurrent = findobj('Tag','Plot')
figure(MakeFigureCurrent)
hold on
end
Some day I ll be a MatLabGOD...but not in this life

Más respuestas (2)

Azzi Abdelmalek
Azzi Abdelmalek el 7 de Ag. de 2014
Use hold on
  4 comentarios
Max Müller
Max Müller el 7 de Ag. de 2014
The problem is: hold on doesnt work as long as i have the Plot=figure command. However i need the the Plot = figure command. Otherwise, matlab displays the plot inside my GUI.
Adam
Adam el 7 de Ag. de 2014
Plot = figure;
hAxes = gca;
hold on
plot( hAxes,... )
allows you to get the axes handle from the first new figure you open and use this to plot on next time

Iniciar sesión para comentar.


Geoff Hayes
Geoff Hayes el 7 de Ag. de 2014
Max - consider renaming your figure handle from Plot to (say) plotFigHandle or something that is a little different from the MATLAB built-in function plot.
Once you have create the figure, then try grabbing the current axes from that figure and setting the hold property to on
plotFigureHandle = figure;
set(plotFigureHandle, 'Position', [306,200, 1610,1085]);
set(plotFigureHandle,'name','Plot','numbertitle','off');
plotAxesHandle = gca;
hold(plotAxesHandle,'on');
And then you can plot multiple plot lines to the figure using the plotAxesHandle
x=-2*pi:0.0001:2*pi;
y=sin(x);
plot(plotAxesHandle,x,y,'b')
plot(plotAxesHandle,x,y+0.5,'r')
Try the above and see what happens!
  4 comentarios
Geoff Hayes
Geoff Hayes el 7 de Ag. de 2014
Max - what you wanted to do wasn't very clear from your question which was how can I add more Plot lines without opening a new figure?
The alternative to assigning a Tag value, is to just save the plotFigureHandle and/or plotAxesHandle to the handles structure and use guidata. Presumably you are using GUIDE, and within a callback you are trying to create the figure and so one of the inputs to this callback is handles
function someWidget_Callback(hObject, eventdata, handles)
% if the plot figure handles is not a field of handles, then
% create it
if ~isfield(handles.plotFigureHandle)
plotFigureHandle = figure;
set(plotFigureHandle, 'Position', [306,200, 1610,1085]);
set(plotFigureHandle,'name','Plot','numbertitle','off');
plotAxesHandle = gca;
hold(plotAxesHandle,'on');
handles.plotFigureHandle = plotFigureHandle;
handles.plotAxesHandle = plotAxesHandle;
guidata(hObject,handles);
end
Adam
Adam el 7 de Ag. de 2014
Editada: Adam el 7 de Ag. de 2014
If you just want to bring a previous axes handle to be the current one you can type:
axes( plotAxesHandle )
if you want to return to the same axes some time later on when you can't assume that gca points to the correct axes.
Personally I don't like doing this and prefer to pass the axes handle to the plot function as this just plots in the correct place instead of bringing the figure containing the axes to the foreground (which I don't always want) which is what the command above does.
Remember though that the plot function associates to an axes handle, not explicitly to a figure handle so just keeping the figure handle is not enough.

Iniciar sesión para comentar.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by