Azzera filtri
Azzera filtri

Plotting contours with additional condition

7 visualizzazioni (ultimi 30 giorni)
Theo
Theo il 13 Lug 2011
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?

Risposte (1)

Rick Rosson
Rick Rosson il 13 Lug 2011
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.

Categorie

Scopri di più su Contour Plots in Help Center e File Exchange

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by