makedist 'PiecewiseLinear'

11 views (last 30 days)
Brian Wood
Brian Wood on 3 Apr 2020
The code below is almost verbatim from the Matlab documentation regarding the use of makedist with 'PiecewiseLinear'. It works as expected.
clear
load hospital
[f,x] = ecdf(hospital.Weight)
f2 = f(1:5:end); % keep a less dense grid of points
x2 = x(1:5:end);
fig1=figure;
hold on
pd3 = makedist('PiecewiseLinear','x',x2,'Fx',f2)
hist = pdf(pd3,x);
stairs(x,hist)
With a very minor modificaiton, the 'PiecewiseLinear' command throws and error.
clear
load hospital
[f,x] = ecdf(hospital.Weight)
f2 = f(1:1:end); % keep the original grid of points
x2 = x(1:1:end);
fig1=figure;
hold on
pd3 = makedist('PiecewiseLinear','x',x2,'Fx',f2)
hist = pdf(pd3,x);
stairs(x,hist)
The error is
Error using prob.PiecewiseLinearDistribution>checkParams (line 226)
X must be a row vector of at least two sorted real values.
Error in prob.PiecewiseLinearDistribution (line 98)
checkParams(x,Fx);..........
I am deeply confused as to why it would suddenly throw an error. The vectors x2 and f2 seem to meet the criteria for appropriate input.
Any help would be appreciated.

Answers (1)

Harsha Priya Daggubati
Harsha Priya Daggubati on 6 Apr 2020
Hi,
Your vector X has to be strictly increasing (X1<X2). I can see X(1) and X(2) are equal to 111. This is causing the issue.
Hope this helps!

Products


Release

R2019b

Community Treasure Hunt

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

Start Hunting!