refreshdata loop issues

Hello, I am a beginner using Matlab R2011a to try to create a simulation which updates a plot in real time. In a different function I import a 100x2x100 matrix which has x and y coordinates and various frames in time. (matrix O) The matrix is solve earlier but I try to display it by refreshing the data at intervals of 0.5 seconds.
function refreshd(O)
lim = max(O(:,1,1)); % boundaries of plot axis
S = size(O,3); % maximum time frames
a = O(:,1,1); % x coordinates (time 0)
b = O(:,2,1); % y coordinates (time 0)
h = plot(a,b,'o','MarkerEdgeColor','g','MarkerFaceColor','g');
set(gca,'Color','k');
set(h,'XDataSource','a','YDataSource','b');
for i = 2:S
pause(0.5)
a = O(:,1,i); % x coordinates (time i)
b = O(:,2,i); % y coordinates (time i)
refreshdata
end
The original plot displays perfectly, and if I manually plot the other times in debug they also display nicely. When I use refreshdata however it just displays a distorted single line which is incorrect. Even if I put refreshdata immediately after I plot the time 0 coordinates (before updating any data) i get the same distorted result which doesn't make sense to me. I have been able to make examples of this work in the workspace but for some reason not here.

Answers (2)

Drop:
set(h,'XDataSource','a','YDataSource','b');
and use in the loop:
set(h,'xdata',O(:,1,ii),'Ydata',O(:,2,ii))
note i stand for irrational so don't use it.
The refreshdata documentation says, "Note that the variable assigned to the data source property must be in the base workspace." This applies unless you use
refreshdata(h, 'caller')

Asked:

on 20 Jul 2011

Community Treasure Hunt

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

Start Hunting!