Removing complex numbers from a set of data
91 views (last 30 days)
Show older comments
I am trying to plot a set of data as a surf plot. The y and x data are fine. However, the z data comes in the form of a complex number. I am trying to zero all of the complex parts so that i can plot it.
y = ydata;
x = xdata;
z = dat.smx; %getting the data from a structure array
z =complex(real(z),0.);
surf(x,y,z)
This acheives what i want and gives me my 192x4096 of only real numbers but the variable is still saved as a complex double so matlab still does not let me plot it.
z(imag(z) ~= 0) = 0;
I tried another way with the above line, which does also remove the imaginary part and does make it a normal double which can be plotted. But it also ends up completely zeroing all but two rows of my data.
763996.405269850 + 0.00000000000000i -6378786.63933523 + 0.00000000000000i
830122.423191093 - 394079.620750282i -5091297.01649812 + 2603687.55800279i
967512.178415854 - 1059879.31296563i -2457122.99646261 + 3059394.68904817i
752434.554058071 - 2280059.15542211i -896237.599749785 + 1334068.00008166i
-658985.067753466 - 3695451.52098837i -1627383.69202439 - 594734.648456007i
My data looks like a larger version of above
Any help is appreciated
0 Comments
Accepted Answer
Dave B
on 12 Aug 2021
Edited: Dave B
on 12 Aug 2021
If you want to make a surf of the real component of z:
surf(x,y,real(z))
If you want to make a surf of the complex magnitude of z:
surf(x,y,abs(z))
Quick example of getting real component/magnitude of a complex number:
a=[1+1i 1-1i 3+3i]
real(a)
abs(a)
0 Comments
More Answers (0)
See Also
Categories
Find more on 2-D and 3-D Plots 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!