Problem when plotting the figure
2 ビュー (過去 30 日間)
古いコメントを表示
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 件のコメント
採用された回答
Star Strider
2020 年 9 月 6 日
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 件のコメント
Star Strider
2020 年 9 月 6 日
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.)
.
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Tables についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!