Matrix - empty selected cells

2 次查看(过去 30 天)
Lizan
Lizan 2011-12-10
So I have a matrix with some real and some real and imaginary part. .. for example
M = [ 1.23 1.34-4i 275-5i 4; 1.56 1.67 3-3i 5-6i];
I would like to remove the ones with an imaginary part so when I plot them real(M) the real number of the ones that had an imaginary part does not appear and is empty. I need to remember the positions because row and col represent the height and width in my plot.
Is this possible? How on earth can I do this?
When I wrote plot(real(M)).. all the real numbers is plotted even those that had an imaginary part. I just don't seem to figure this out.
Many thanks for assistance... to this conundrum.

回答(1 个)

Paulo Silva
Paulo Silva 2011-12-10
You might encounter problems when removing values from array because the dimensions must be consistent
M = [ 1.23 1.34-4i 275-5i 4; 1.56 1.67 3-3i 5-6i];
MM=M; %don't overwrite your original data
MM(imag(M)~=0)=NaN %replace values with imaginary parts
%apply your code to MM, the NaN values are ignored by the plot function
plot(MM)

类别

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

产品

Community Treasure Hunt

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

Start Hunting!

Translated by