Azzera filtri
Azzera filtri

using linkdata on existing figures

11 visualizzazioni (ultimi 30 giorni)
Art
Art il 9 Apr 2012
Commentato: Scott il 13 Dic 2013
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.

Risposte (2)

Walter Roberson
Walter Roberson il 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.
  2 Commenti
Art
Art il 9 Apr 2012
Walter - at various times I have tried including
set(h1,'XDataSource','systime_value')
after the plot command.
I still get an error.
Art
Art il 9 Apr 2012
Actually, I think I may be able to do this without using linkdata at all. If I just update the XData value each time through the line updates as I want it to.
Thanks

Accedi per commentare.


Scott
Scott il 12 Dic 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 Commento
Scott
Scott il 13 Dic 2013
also don't forget to 'refreshdata(handles.figure1,'caller')' to force a refresh of your GUI. This is similar to using 'drawnow'.

Accedi per commentare.

Categorie

Scopri di più su Visual Exploration in Help Center e File Exchange

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by