using linkdata on existing figures
13 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
I have a gui that displays a movie frame by frame.
There are also plots of various data pertaining to the movie in separate figures.
I would like to link the plots to the movie frame time and display a vertical line on any existing figures that is located at the current movie frame time.
the code I am trying is various forms of:
%%get list of current figures:
fig_list = findobj('Type','figure')
figure(fig_list(1)) %%first fig only right now
ylims = get(gca,'YLim');
h1 = plot([systime_value systime_value], [ylims]);
linkdata(h1, 'on')
This prints a vertical line at the current time, but I get errors on the linkdata part, and the line is redrawn every iteration.
I am also running this from a subfunction that passes in "systime_value". Maybe this is the problem?
Thanks for any input.
0 Kommentare
Antworten (2)
Walter Roberson
am 9 Apr. 2012
When a figure containing graphs is linked and any variable identified as XDataSource, YDataSource, and/or ZDataSource changes its values in the workspace, all graphs displaying it in that and other linked figures automatically update.
In your code, I do not see that you have set any *DataSource variable.
Scott
am 12 Dez. 2013
Came across this and it helped me, but here is what I did in my GUI.
My GUI contains several input fields, buttons and one axes that I named plot1 and want to update as data arrives or is taken.
My opening function for the gui initializes the plot and links the data.
function MyGuiName_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% varargin command line arguments to VoltageRamp (see VARARGIN)
% Choose default command line output for VoltageRamp
handles.output = hObject;
% Create variables and timer objeect
handles.xData=[];
handles.yData=[];
% Initialize the plot, then define and link the data sources
plot(handles.plot1,1,1,'LineWidth',2);
set(get(handles.plot1,'Children'),'XDataSource','handles.xData');
set(get(handles.plot1,'Children'),'YDataSource','handles.yData');
linkdata on;
% hide the stupid banner that pops up to show that data is linked
dpm=datamanager.linkplotmanager;
dpm.Figures.Panel.close;
% Update handles structure
guidata(hObject, handles);
Then any time I update handles.xData and handles.yData, the plot will update. In my case, a timer object updates them periodically and a few different buttons update them on demand. Just don't forget to issue guidata(hObject, handles); after a callback has retrieved and updated the variables.
1 Kommentar
Scott
am 13 Dez. 2013
also don't forget to 'refreshdata(handles.figure1,'caller')' to force a refresh of your GUI. This is similar to using 'drawnow'.
Siehe auch
Kategorien
Mehr zu Graphics Objects finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!