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.
回答(2 个)
Oleg Komarov
2011-7-20
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.
Walter Roberson
2011-7-20
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')
类别
在 帮助中心 和 File Exchange 中查找有关 Annotations 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!