Call 2D real functions with complex numbers (cmplx.m)
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.
Zitieren als
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. Abgerufen .
Kompatibilität der MATLAB-Version
Plattform-Kompatibilität
Windows macOS LinuxKategorien
Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Live Editor erkunden
Erstellen Sie Skripte mit Code, Ausgabe und formatiertem Text in einem einzigen ausführbaren Dokument.
Version | Veröffentlicht | Versionshinweise | |
---|---|---|---|
1.0.0.0 |