Problem when plotting the figure
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
yusra Ch
am 6 Sep. 2020
Kommentiert: Star Strider
am 6 Sep. 2020
I have a vector called K [622x1] double I plot the PDF of K . I fitted my K vector to the Gaussian mixture distribution and ploted the PDF with a solid line :
>> GMModel = fitgmdist(k,2);
>> gm=gmdistribution(GMModel.mu,GMModel.Sigma);
>> pdfk=pdf(gm,k);
>> figure
>> plot(k,pdfk)
The plot has several lines and I dont know what is the problem and how to resolve it. Ca anyone help me with this? thank youuu
0 Kommentare
Akzeptierte Antwort
Star Strider
am 6 Sep. 2020
I do not have ‘k’, so I created my own, and was able to reproduce essentially the result you got.
The multiple lines disappear of you sort ‘k’ first:
k = sum([randn(622,1)+5; randn(622,1)+1],2);
k = sort(k); % <— ADD ‘sort’ CALL
GMModel = fitgmdist(k,2);
gm=gmdistribution(GMModel.mu,GMModel.Sigma);
pdfk=pdf(gm,k);
figure
plot(k,pdfk)
.
4 Kommentare
Star Strider
am 6 Sep. 2020
I would do something like this (starting with my original code):
k = sum([randn(622,1)+5; 0.5*randn(622,1)+1],2);
k = sort(k); % <— ADD ‘sort’ CALL
GMModel = fitgmdist(k,2);
gm=gmdistribution(GMModel.mu,GMModel.Sigma);
pdfk=pdf(gm,k);
[f,x] = ecdf(k); % Empirical Cumulative Distribution Function
[fr,xr] = resample(f, x); % Resample To Constant Sampling Interval
df = gradient(fr)./gradient(xr); % Calculate Derivative To Get PDF
dfs = smoothdata(df, 'gaussian', 150); % Smooth To Eliminate Noise
figure
plot(k,pdfk)
hold on
plot(xr, dfs)
hold off
This appears to produce a reasonable approximation. Experiment with the smoothdata function (introduced in R2017a) with your data to get different results. (I do not kinow what MATLAB version you are using. Other options, such as movmedian to do the smoothing were introduced in R2016a, and of course there are still other options.)
.
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Tables finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!