I try also:

polyfit(x,y,2);

6 views (last 30 days)

Show older comments

I have this figure

and I want to draw a line between the head of first bar (at x=-25) and the end of the red curve(at x=0) like this:

I try to draw the line using the exponential distribution

EEPY=0.019522:-0.00069:0.00172441;

mu=expfit(EEPY); % n estimate parameters maximum likelihood exponential

xgride = linspace(-25,0,100);

Ee=exppdf(xgride,mu);

line(xgride,Ee,'color','g')

and I try another way to draw the line

EEPY=0.019522:-0.00069:0.00172441;

EEPX=-25:1:0

xvaluese=linspace(min(EEPX),max(EEPX));

yvaluese=interp1(EEPX,EEPY,xvaluese,'spline');

plot(xvaluese,yvaluese,'g--') % this plot a straight line

but I got nothing...

how I could match the two points

Kelly Kearney
on 10 Nov 2015

expdf fits a pdf to a distribution of points... it doesn't define the pdf at given x-coordinates. So in your code, you're fitting an exponential distribution to uniform data (the x-coordinates), which is of course not what you want.

If you just want a curve following the approximate shape of a negative exponential, then I recommend defining the curve explicitly, rather than messing with fitting:

x1 = -25; % Coordinates of first bar

y1 = 0.015;

x2 = 0; % Coordinates of red line start

y2 = 0.0025;

dy = y1 - y2;

dx = x2 - x1;

k = 1;

f = @(x) dy.*exp(-k*(x + dx)) + y2;

x = linspace(x1, x2, 50);

y = f(x);

You can adjust the k parameter to get a steeper or shallower drop-off in the curve.

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

Start Hunting!