Call 2D real functions with complex numbers (cmplx.m)

A wrapper function to allow use of complex numbers in functions of the form F(X,Y,...).

You are now following this Submission

I frequently store X,Y vector data as a single complex vector V = X + iY. This makes for easy translation, rotation and scaling manipulation. Distances between data points and dot and cross products are also easy in the complex plane.

For functions that require the form F(X,Y,...), such as SCATTER, I get tired of typing:
SCATTER(REAL(V), IMAG(V), SIZE, COLOR);
With this function, SCATTER would be called like this:
CMPLX(@SCATTER, V, SIZE, COLOR);

The advantage of this method is clearer when you start to put cuts into your data. For example, here if I change the cut variable, then I only have to alter it in one place:

CUT1 = FIND(ABS(V) > 3.5);
CMPLX(@SCATTER, V(CUT1), SIZE, COLOR);

This function does not alter the shape of your inputs. If the function requires column vectors, then use "(:)" on V:

CMPLX(@F, V(:), ...);

This is a stupidly short function, but I hope you find it useful.

Cite As

Peter Mao (2026). Call 2D real functions with complex numbers (cmplx.m) (https://www.mathworks.com/matlabcentral/fileexchange/42123-call-2d-real-functions-with-complex-numbers-cmplx-m), MATLAB Central File Exchange. Retrieved .

General Information

MATLAB Release Compatibility

  • Compatible with any release

Platform Compatibility

  • Windows
  • macOS
  • Linux
Version Published Release Notes Action
1.0.0.0