pdf and unifpdf functions not working

2 views (last 30 days)
Afeef Akhtar
Afeef Akhtar on 6 Apr 2022
I am trying to get the Primary Distribution Function and have been using pdf functions to get them. They were working just fine last week but for some reason, they're not this time. I have even tried to use help for pdf and unifpdf and Matlab is telling me that they're undocumented builtin functions. In my code, the errors I am recieving are in lines 38 and 40. I am not sure if its because of an update or not. Would anyone have any solutions to this?
Here is my matlab code:
close all
clear all
x = randn(1,10000);
y = randn(1,10000)+1;
%x_cdf_graph = [0:0.1:8];
mu_x = mean(x);
var_x = var(x);
std_x = sqrt(var_x);
sigma_x = mean(x.^2)-mu_x^2
theta_x = var_x/mu_x;
k_x = mu_x/theta_x;
mu_y = mean(y);
var_y = var(y);
std_y = sqrt(var_y);
sigma_y = mean(y.^2)-mu_y^2
theta_y = var_y/mu_y;
k_x = mu_y/theta_y;
cov_x_y = cov(x,y);
E_xy = mean(x.*y)
E_w_x = mu_x/max(x);
Var_w_x = var_x/(max(x)^2);
autocorr_x = xcorr(x);
pow_x = fft(autocorr_x);
autocorr_y = xcorr(y);
pow_y = fft(autocorr_y);
row_xy = (E_xy - mu_x*mu_y)/(std_x*std_y)
r = xcorr(x, y);
z = 0:0.1:1;
pdf_x = pdf('Normal',[0:0.1:1], 0, 1)
pdf_y = unifpdf([0:0.1:1], 0, 1)
nbins_x = 25;
hist_x = histogram(x)
hNormalized_x = hist_x.Values / sum(hist_x.Values);
cdf_x = cumsum(hNormalized_x);
nbins_y = 25;
hist_y = histogram(y)
hNormalized_y = hist_y.Values / sum(hist_y.Values);
cdf_y = cumsum(hNormalized_y);
lin_est = row_xy*(std_y/std_x)*(x - mu_x) + mu_y
%X = [histogram(x)]
% hist_x = histogram(x);
% grid on;
% Figures 1 and 2 are histogram and CDF of x[n]
figure(1)
plot([0:0.1:1],pdf_x*500);
hold on
histogram(x);
figure(2)
plot(cdf_x);
% Figures 3 and 4 are histogram and CDF of y[n]
figure(3)
plot([0:0.1:1],pdf_y*500);
hold on
histogram(y);
figure(4)
plot(cdf_y);
% Figure 5 is the linear estimation x[n] and y[n]
figure(5)
plot(x,lin_est, x(1:500), y(1:500), '.');
% Figures 6 and 7 are the autocorrelation of x[n] and y[n]
figure(6)
plot(autocorr_x);
figure(7)
plot(autocorr_y);
% Figures 8 and 9 are power spectrums of x[n] and y[n]
figure(8)
plot(abs(pow_x));
figure(9)
plot(abs(pow_y));
% Joint pdf for x and y
figure(10)
hist3([x;y]');
% Figure 11 Joint cdf for x and y
mu = [0 1];
Sigma = [1 0; 0 1];
[A1,A2] = meshgrid(linspace(-10,10,25)',linspace(-10,10,25)');
A = [A1(:) A2(:)];
p = mvncdf(A,mu,Sigma);
Z = reshape(p,25,25);
figure(11)
surf(A1,A2,Z)

Answers (1)

Prahlad Gowtham Katte
Prahlad Gowtham Katte on 14 Apr 2022
Hello Afeef
As per my understanding of your query there is something wrong with pdf and unifpdf functions. The code snippet you’ve shared seems to be working in my end. Please make sure that you have not named any script that you wrote as pdf.m or unifpdf.m.
Here is the link of documentation of those functions.
Hope it helps!

Tags

Community Treasure Hunt

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

Start Hunting!