counting and plotting elements in a vector

조회 수: 5 (최근 30일)
Ahsan Khan
Ahsan Khan 2013년 10월 7일
댓글: Ahsan Khan 2013년 10월 8일
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

답변 (1개)

Image Analyst
Image Analyst 2013년 10월 7일
for k = 1 : length(v)
plot(k, v(1:k), 'bo-');
drawnow;
pause(0.5);
end
  댓글 수: 1
Ahsan Khan
Ahsan Khan 2013년 10월 8일
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.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Graphics Objects에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by