counting and plotting elements in a vector

5 views (last 30 days)
Ahsan Khan
Ahsan Khan on 7 Oct 2013
Commented: Ahsan Khan on 8 Oct 2013
hi there, i want to count the number of elements in a vector and plot it right away. ex: v = [2,3,2,4,5,6,5,6,7,] the out put should be plotted right away. so the a plot should be made whos x-axis extends from 1 - 10 (y depends on counts so doesnt matter) so for the first plot, since there are no 1s...no count(or 0) is plotted then that plot is held and the count of 2 is plotted so it will be one, then next is 3 - one again, next is 2 in the vector but now we have gone up to count two so two is plotted and so on. so basically i want to plot the counts as the loop is run through the vector and the plot is updated with each loop. any help would be appreciated. thanks

Answers (1)

Image Analyst
Image Analyst on 7 Oct 2013
for k = 1 : length(v)
plot(k, v(1:k), 'bo-');
drawnow;
pause(0.5);
end
  1 Comment
Ahsan Khan
Ahsan Khan on 8 Oct 2013
hi there, thanx 4 the reply but this isn't what i want. let me explain again. say i have a column vector: v = [1;4;5;1;5;1]. i want to plot this with x-axis being the numbers 1-5 and y-axis being the count of occurrence of the number.so the first plot will (1,1), cause 1 have only occurred once, then the next plot will be (4,1) cause 4 occurred once, then (5,1). the next plot now will be (1,2) cause now 1 has occurred twice, then the next plot will be (5,2) cause 5 have now occurred twice. then the next plot will be (1,3) cause now 1 has occurred three times. note that all the previous plots should be held and plotted as well. i have also attached an image illustrating the procedure, even though it shows six separate plots, all of it is actually happening on one
. please help. thanx in advance.

Sign in to comment.

Categories

Find more on Graphics Objects in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!