필터 지우기
필터 지우기

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 CenterFile Exchange에서 Contour Plots에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by