Removing complex numbers from a set of data

84 次查看(过去 30 天)
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

采纳的回答

Dave B
Dave B 2021-8-12
编辑:Dave B 2021-8-12
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]
a =
1.0000 + 1.0000i 1.0000 - 1.0000i 3.0000 + 3.0000i
real(a)
ans = 1×3
1 1 3
abs(a)
ans = 1×3
1.4142 1.4142 4.2426

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Line Plots 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by