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 Center および File ExchangeLogical についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by