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

조회 수: 1 (최근 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