フィルターのクリア

Plotting contours with additional condition

7 ビュー (過去 30 日間)
Theo
Theo 2011 年 7 月 13 日
Let f(z) be a complex function. Suppose I wanted to plot the contours where the imaginary part, imag(f(z)) = 0, but the real part positive. An example code would be
% Mesh
x = linspace(-2, 2, 50);
y = linspace(-2, 2, 50);
[xmat, ymat] = meshgrid(x, y);
z = xmat + 1i*ymat;
% Function
f = sqrt(z);
% Contour
[C, h] = contour(x, y, imag(f), [0 0]);
This gives me the contours with imag(f) == 0. However, I'd like to only plot contours with imag(f) == 0 && real(f) >= 0. Is there an easy way to do this?

回答 (1 件)

Rick Rosson
Rick Rosson 2011 年 7 月 13 日
Please try the following:
thresh = 0.02;
idx = ( (abs(imag(f)) < thresh) & (real(f)>=0) );
[C, h] = contour(x, y, idx, [ 1 1 ]);
This approach is highly dependent on the choice of value for thresh. So it's not a perfect solution, but it is a possibility.
HTH.

カテゴリ

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by