Logical Indexing with Complex Numbers
Show older comments
So I have a data set of coefficients which are calculated from a Laplace expansion into spherical harmonics. The resulting coefficients can be either real or complex. When I'm working though the data, there are times all (or a lot) the imaginary components have values << eps i.e the numerical accuracy (so in one dataset of 100,000 or so coefficents, the max imaginary component is 2e-17 compared to a max coefficient of 120).
For the purposes of my work, the presence of the imaginary numbers is bad for both clarity and computational time.
For a variable A;
I can use the code
A(A<=eps)=0
to zero the effectively zero real components however the logical '<' ignores imaginary numbers. I did a lot of searching and can't seem to find a method to do the same with the imaginary component.
I believe it maybe possible to break up the matrix using real and imag, set the zeros and then reassign the initial matrix with the new imaginary components, howver I'm unsure of a consise way to do this and I would imagine the 4 lines of code I can write would become cumbersome when I'm working with lots of data and loops etc
Any ideas or suggestions would be much appreicated
1 Comment
ADSW121365
on 9 May 2019
Accepted Answer
More Answers (0)
Categories
Find more on Creating and Concatenating Matrices in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!