What is my syntax lacking to achieve an accumulative-progressing animation of the plot?

C
CHUN HIN KYLE · Jan 8, 2024 · 2K views
Question
hold on for idx = 1:10 plot(idx, density(idx),"*") drawnow xlim([0.0 10.0]) ylim([0.0 6.1]) hold on plot(1:idx, density(1:idx),"*") drawnow end Unrecognized function or variable 'density'.  
Expert Answer
Profile picture of Kshitij Singh
Kshitij Singh PhD Expert
Answered Aug 14, 2026
I assume you want to add a point to the graph iteration wise.
 
In that case, try this -
 
%Sample values
density = rand(1,10);

%Initialize an animated line with specifications as needed
h = animatedline('Marker', '*');

for idx = 1:10
    %Add points to the line
    addpoints(h, idx, density(idx))
    %Update the figure
    drawnow
end 

 

100% Run Guarantee 3-Hour Fast-Track Delivery

Need a Custom Version or Complete Simulation for This Problem?

Our 500+ PhD engineers build, debug, and optimize working MATLAB scripts and Simulink (.slx) models tailored to your exact assignment rubrics with zero plagiarism.

Tested on MATLAB R2024b / R2026a
Turnitin 0% Plagiarism Report
Free 7-Day Revisions Guarantee
Have a different question? Ask here

Get a Free Consultation or a Sample Assignment Review!