histogram function, matlab doesnt like my dx

Hey, I am trying to create a function for histogram that takes i the vector v, with n bins and in the interval [a,b]. I created the function but matlab tells me that I using arguments of type 'double'. I think it is because it doesn't like dx not being an integer but I have no idea what to do. Can you please help?
this is my code:
if true
function histarray=myhist(v,a,b,n)
histarray=zeros(1,n);
dx=(b-a)./n;
x=a:dx:b;
for i=1:length(x)
for k=1:length(v)
if (x(i)<=v(k)) && (v(k)<=(x(i)+dx))
histarray(i)=histarray(i)+1;
end
end
end
bar(x,histarray)
end
end
I will really appreciate any help. Kasia

1 Comment

Why don't you just one one of the many built-in histogram functions?

Sign in to comment.

Answers (0)

Asked:

on 4 Mar 2014

Commented:

on 4 Mar 2014

Community Treasure Hunt

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

Start Hunting!