# Kernel Density for 2D data

I have two series of data(both of type double). I want to generate a kernel density plot from these. Pls help. My coding is given below.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

curs1 = exec(conn, 'select sp_x, sp_y from road_part6_trajectories_oneway2_new_segments_cartesian2');format long;curs1 = fetch(curs1);AA = curs1.Data;x = [AA{:,1}]';y = [AA{:,2}]';%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

I want to generate the kernel density or any other suitable density plot for x and y. pls advise.

*NOTE:-*

Matlabsolutions.com provide latest MatLab Homework Help,MatLab Assignment Help , Finance Assignment Help for students, engineers and researchers in Multiple Branches like ECE, EEE, CSE, Mechanical, Civil with 100% output.Matlab Code for B.E, B.Tech,M.E,M.Tech, Ph.D. Scholars with 100% privacy guaranteed. Get MATLAB projects with source code for your learning and research.

The function ksdensity() will do kernel density estimation. It’s not clear to me what your x and y represent, so it’s hard to give more specific advice than that.

In response to comments, here is some code with an example of 2-d kernel density estimation, with a plot of the results. Important note: this assumes that x and y are independent from each other.

% Generate some normally distributed data

x = randn(50,1);

y = randn(50,1);% Estimate a continuous pdf from the discrete data

[pdfx xi]= ksdensity(x);

[pdfy yi]= ksdensity(y);% Create 2-d grid of coordinates and function values, suitable for 3-d plotting

[xxi,yyi] = meshgrid(xi,yi);

**SEE COMPLETE ANSWER CLICK THE LINK**