How can I plot only the real elements in a plot?

31 ビュー (過去 30 日間)
Adrian
Adrian 2014 年 4 月 14 日
コメント済み: Adrian 2014 年 4 月 15 日
Hello.
I have this vector which I want to plot:
[13.0063+5.2866i 13.0063+4.0813i 13.0063+3.1717i 13.0063+2.3909i 13.0063+1.6299i 13.0063+0.6369i 14.1461 14.6237 14.9160 15.1183 15.2658 15.3761 15.6303 15.6466 15.6558 15.6589 15.6568 15.6502 15.6395 15.6253 15.6079 15.5877 15.5648 15.5395 15.5120]
So it's a vector with 29 elements, and id'like to plot it against another vector which is like this:[2:30]
The problem is that the elements that contain imaginary no. mess the graph up because for the complex elements, the real part is constant as you can see.
And my question is if that is a general way so I can plot only from the real no. further (from the 7th in this case), I was thinking maybe about an if function would be helpful, and in case the element has an imaginary part, maybe "skip it", or something like that. I don't know what should be the syntax for this kind of situation, to skip it, and to go to the next element.

採用された回答

Dishant Arora
Dishant Arora 2014 年 4 月 14 日
idx = (testArray==real(testArray)); testArray is the array under consideration.
realComponents = testArray(idx) ;
  1 件のコメント
Adrian
Adrian 2014 年 4 月 15 日
Yes Dishant Arora, that was what I needed. Thank you all very much.

サインインしてコメントする。

その他の回答 (1 件)

Mahak SINGH CHAUHAN
Mahak SINGH CHAUHAN 2014 年 4 月 14 日
You can use real command in order to plot only real numbers where it is imaginary.
e.g: plot(l,real(m))
  1 件のコメント
Dishant Arora
Dishant Arora 2014 年 4 月 14 日
real outputs real part, it doesn't eliminate complex numbers.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeAnnotations についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by