Search code examples
arraysmatlabfunctionpi

Matlab arrayfun


I do this:

A = [pi/2 3*pi/2 3*pi/2 pi];
B = arrayfun(wrapToPi, A);

Expecting B:

[pi/2 -pi/2 -pi/2 pi]

But instead of that, I receive an error message:

Not enough input arguments.

Error in wrapToPi (line 13)
q = (lambda < -pi) | (pi < lambda);

Error in PSK (line 19)
x = arrayfun(wrapToPi,indices2);

Where is the problem?


Solution

  • arrayfun has nothing to do here.

    The correct way of doing that is:

    A = [pi/2 3*pi/2 3*pi/2 pi];
    wrapToPi(A)
    

    which gives:

    ans =
    
        1.5708   -1.5708   -1.5708    3.1416
    

    which is the same as: [pi/2 -pi/2 -pi/2 pi]