How to create 3D joint density plot MATLAB?

前端 未结 3 471
礼貌的吻别
礼貌的吻别 2021-01-07 13:37

I \'m having a problem with creating a joint density function from data. What I have is queue sizes from a stock as two vectors saved as:

X = [askQueueSize b         


        
3条回答
  •  独厮守ぢ
    2021-01-07 13:54

    With help from a guy at mathworks forum, this is the great solution I ended up with:

    (data_x and data_y are values, which you want to calculate at hist3)

    x = min_x:step:max_x; % axis x, which you want to see
    y = min_y:step:max_y; % axis y, which you want to see
    
    [X,Y] = meshgrid(x,y); *%important for "surf" - makes defined grid*
    
    pdf = hist3([data_x , data_y],{x y}); %standard hist3 (calculated for yours axis)
    pdf_normalize = (pdf'./length(data_x)); %normalization means devide it by length of 
                                             %data_x (or data_y)
    figure()
    surf(X,Y,pdf_normalize) % plot distribution
    

    This gave me the joint density plot in 3D. Which can be checked by calculating the integral over the surface with:

    integralOverDensityPlot = sum(trapz(pdf_normalize));
    

    When the variable step goes to zero the variable integralOverDensityPlot goes to 1.0

    Hope this help someone!

提交回复
热议问题