how to plot like in other CAS

hi y is a vector whose vlaues can be any value (whole numbers) from range form 0 999999 . total values in y are few thousands. i want to plot those values where x axis should be from 0 999999 and if a vlaue a y value of 1 for each occurance..
so if y=[33333 44432 33333 111111]
the graph x-axis should be from 0 - 999999 and at x=33333 y value should be 1+1 (two occurances) and at 44432 y value should be 1.,
i made x=1:999999; but when i stem y against x lenghts do not match.
how can i zero fil all values that are not present in y . and set y value an increment of 1 for each occurance.

Answers (2)

uy = unique(y);
counts = histc(y, uy);
bar(uy, counts)
Chamjiee Tramadol
Chamjiee Tramadol on 27 May 2016
Edited: Walter Roberson on 28 May 2016
i am trying to execute below code but unable to match indexes..
y=[contains few thousands six digit values]';
yi=zeros(1,max(y));
for i=1:(max(y)-1)
if (y(i) ~= 0 && (y(i) ~= y(i+1)))
yi(i)=y(i);
else
yi(i) =yi(i)+1;
end
end

This question is closed.

Asked:

on 24 May 2016

Closed:

on 20 Aug 2021

Community Treasure Hunt

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

Start Hunting!