joint pdf calculation and plot

8 次查看(过去 30 天)
Yusuf
Yusuf 2015-9-10
Hi guys,
Having a bit of trouble trying to make a file that calculates and plot the join pdf of 2 variables using 100 bins.
Current attempt which I'm not sure is the best way to go about it
x = A.data(1:57199,2); %gather x data y = A.data(1:57199,3); %gather y data
x_axis = 1:100:57199; % Define edges of bins for x axis. Column vector y_axis = 1:100:57199; % Same for y axis
% Compute corners of 2D-bins: [x_mesh_upper,y_mesh_upper] = meshgrid(x_axis(2:end),y_axis(2:end)); [x_mesh_lower,y_mesh_lower] = meshgrid(x_axis(1:end-1),y_axis(1:end-1));
% Compute centers of 1D-bins: x_centers = (x_axis(2:end)+x_axis(1:end-1))/2; y_centers = (y_axis(2:end)+y_axis(1:end-1))/2;
% Compute pdf: pdf = mean( bsxfun(@le, x(:), x_mesh_upper(:).') ... & bsxfun(@gt, X(:), x_mesh_lower(:).') ... & bsxfun(@le, Y(:), y_mesh_upper(:).') ... & bsxfun(@gt, Y(:), y_mesh_lower(:).') ); pdf = reshape(pdf,length(x_axis)-1,length(y_axis)-1); % pdf values at the % grid points defined by x_centers, y_centers pdf = pdf ./ (y_mesh_upper-y_mesh_lower) ./ (x_mesh_upper-x_mesh_lower); % normalize pdf to unit integral
% Plot pdf figure imagesc(x_centers,y_centers,pdf) axis xy axis equal colorbar title 'pdf'
Thanks in advance guys!

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Loops and Conditional Statements 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by