Matrix - empty selected cells

2 views (last 30 days)
Lizan
Lizan on 10 Dec 2011
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.

Answers (1)

Paulo Silva
Paulo Silva on 10 Dec 2011
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)

Products

Community Treasure Hunt

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

Start Hunting!