MATLAB: Getting NaN using normcdf with array inputs


I want to get two arrays of data using normcdf, each with its own sigma. So (in both R2019a and R2018a) I tried something like
which is supposed to output a 3*2 matrix whose columns contain the data corresponding to the same sigma, right? However, what I got is
>> normcdf((-1:1)',0,[.5,.2])
ans =
0.0228 NaN
0.5000 NaN
It works perfectly if I just have one parameter being an array. Am I using normcdf in a wrong way? Thank you for any suggestions.

Best Answer

  • If one or more of the input arguments x, mu, and sigma are arrays, then the array sizes must be the same.
    Your x is 3 x 1, your sigma is 1 x 2. You are violating the array size compatibility rule.
    You need to repmat your sigma to has as many rows as x has.