필터 지우기
필터 지우기

using linkdata on existing figures

조회 수: 11 (최근 30일)
Art
Art 2012년 4월 9일
댓글: Scott 2013년 12월 13일
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.

답변 (2개)

Walter Roberson
Walter Roberson 2012년 4월 9일
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
Art
Art 2012년 4월 9일
Walter - at various times I have tried including
set(h1,'XDataSource','systime_value')
after the plot command.
I still get an error.
Art
Art 2012년 4월 9일
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

댓글을 달려면 로그인하십시오.


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

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Visual Exploration에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by