Is there any way to refresh a graph partly using 'drawnow'?
7 次查看(过去 30 天)
显示 更早的评论
I am designing an animation. I have many different object to draw. Some of them moves on the graph. That's why, they need to update in each iteration. Some of them is stationary. In this case, it is enough to draw them just once. Is there any way to use drawnow for refreshing entire animation except stationary ones. If not, what are the alternatives of drawnow?
0 个评论
采纳的回答
Jack
2023-3-26
Hi,
Yes, you can use the drawnow function to refresh the animation, but only update the objects that need to be updated. One way to achieve this is by keeping track of which objects are stationary and which ones are moving.
For example, you can create a list of moving objects and a list of stationary objects, and then update only the moving objects in each iteration:
moving_objects = [obj1, obj2, obj3]; % list of moving objects
stationary_objects = [obj4, obj5, obj6]; % list of stationary objects
while animation_is_running
% update moving objects
for i = 1:length(moving_objects)
update_object_position(moving_objects(i)); % update object position
draw_object(moving_objects(i)); % draw object
end
% refresh the animation
drawnow;
end
Alternatively, you can use the set function to update the properties of the moving objects directly, without redrawing the entire animation each time:
moving_objects = [obj1, obj2, obj3]; % list of moving objects
stationary_objects = [obj4, obj5, obj6]; % list of stationary objects
while animation_is_running
% update moving objects
for i = 1:length(moving_objects)
update_object_position(moving_objects(i)); % update object position
set(moving_objects(i), 'XData', new_xdata, 'YData', new_ydata); % update object data
end
% refresh the animation
drawnow;
end
This approach can be faster and more efficient, as it avoids redrawing the entire animation each time.
0 个评论
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!