how can I change the code to have only unique CDF and PDF plot?not for all samples

2 次查看(过去 30 天)
mu = 1;
sigma = 5; % make the distribution as wide as we want.
N = 100;
randgeneration = randn(N,1)*sigma + mu;
pdfNormal = normpdf(randgeneration, mu, sigma);
figure;
subplot(2,2,1)
plot(randgeneration, pdfNormal);
xlabel('randomgeneration');
ylabel('pdfNormal');
subplot(2,2,2)
histogram(randgeneration);
subplot(2,2,3)
histfit(randgeneration);
subplot(2,2,4);
pd=makedist('Normal'); %create probability distribution object
cumulativedis=cdf(pd,randgeneration);
plot(randgeneration,cumulativedis,'r-.');
xlabel('randgeneration');
ylabel('CDF');
disp(mean(randgeneration));
disp(std(randgeneration))

采纳的回答

Star Strider
Star Strider 2022-5-16
I am not absolutely certain what you want.
If you want one plot for the first and last subplots, rather than multiple lines in each one, sort them by first sorting ‘randgeneration’ and using that index for it and the others (the second and third subplots are histograms, so the order is irrelevant for them) —
mu = 1;
sigma = 5; % make the distribution as wide as we want.
N = 100;
randgeneration = randn(N,1)*sigma + mu;
[~,ix] = sort(randgeneration); % Create Sorting Index
pdfNormal = normpdf(randgeneration, mu, sigma);
figure;
subplot(2,2,1)
plot(randgeneration(ix), pdfNormal(ix));
xlabel('randomgeneration');
ylabel('pdfNormal');
subplot(2,2,2)
histogram(randgeneration);
subplot(2,2,3)
histfit(randgeneration);
subplot(2,2,4);
pd=makedist('Normal'); %create probability distribution object
cumulativedis=cdf(pd,randgeneration);
plot(randgeneration(ix),cumulativedis(ix),'r-.');
xlabel('randgeneration');
ylabel('CDF');
disp(mean(randgeneration));
1.2960
disp(std(randgeneration))
4.6708
.

更多回答(0 个)

Community Treasure Hunt

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

Start Hunting!

Translated by