www.gusucode.com > matlab 案例源码 matlab代码程序 > matlab/PlotRealAndImaginaryPartsOfSignFunctionExample.m

    %% Plot Real and Imaginary Parts of Sign Function
% Plot real and imaginary parts of the sign function over $-3 < x < -3$ and $-3
% < y < 3$.
% 
% First, create a mesh of values over |-3 < x < 3| and |-3 < y < 3| using
% |meshgrid|. Then create complex numbers from these values using |z = x + 1i*y|.

% Copyright 2015 The MathWorks, Inc.

v = -3:0.1:3;
[x, y] = meshgrid(v);
z = x + 1i*y;
%%
% Find the real and imaginary parts of the sign function of |z|.
s = sign(z);
re = real(s);
im = imag(s);
%%
% Plot the real and imaginary parts.
surf(x,y,re)
title('Real part of sign function')
xlabel('x')
ylabel('y')
figure(2)
surf(x,y,im)
title('Imaginary part of sign function')
xlabel('x')
ylabel('y')