MATLAB Answers


Integrating mnvpdf using integral2

Asked by Scott
on 21 Aug 2013


I have a question about integrating mvnpdf using integral2. I have

    myPDF = @(x,y) mvnpdf([x,y],[1,2],[1,0;0,1])
    result = integral2(myPDF,-100,100,-100,100);

When I try to run this I get the error:

Error using mvnpdfX
X and MU must have the same number of columns

Thanks for your help...



No products are associated with this question.

1 Answer

Answer by Shashank Prasanna
on 21 Aug 2013
 Accepted answer

From the documentation of intergral2:

The function fun must accept two arrays of the same size and return an array of corresponding values. It must perform element-wise operations

Your function does not do element wise operation. As a workaround you will have to write up a function file where you can check if one of x or y is a single element and replicate it to be a vector of constants.


Join the 15-year community celebration.

Play games and win prizes!

Learn more
Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

MATLAB Academy

New to MATLAB?

Learn MATLAB today!