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

Version 1.0.0.0 (1.18 KB) by Peter Mao
A wrapper function to allow use of complex numbers in functions of the form F(X,Y,...).
219 Downloads
Updated 6 Jun 2013

View License

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 (2024). 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 .

MATLAB Release Compatibility
Created with R2013a
Compatible with any release
Platform Compatibility
Windows macOS Linux
Categories
Find more on Scatter Plots in Help Center and MATLAB Answers

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!
Version Published Release Notes
1.0.0.0