fitting a custom curve in histogram

7 views (last 30 days)
cgo
cgo on 15 Feb 2015
Edited: Star Strider on 15 Feb 2015
Hello,
I have a histogram plot data and I want to fit some curve that is "non-traditional". Instead of the usual normal, beta, etc plots, I want to fit it with something like log(c/x) where c is a constant. Any ideas on how to achieve this?
Thanks

Answers (1)

Star Strider
Star Strider on 15 Feb 2015
Edited: Star Strider on 15 Feb 2015
One possibility:
bars = randi(20, 1, 5); % Created ‘Histogram’ Data
bins = 1:5;
f = @(c,x) log(c./x);
B0 = rand;
B = nlinfit(bins, bars, f, B0);
figure(1)
bar(bins, bars)
hold on
plot(bins, f(B,bins), '-r', 'LineWidth',1.5)
hold off
You will have to experiment with it to get the result you want. I can only claim that the code I posted here runs!

Community Treasure Hunt

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

Start Hunting!