Global Index (short | long) | Local contents | Local Index (short | long)
[h, c] = pncont(xa, ya, x, clev, lab, s);
[h, c] = pncont(xa, ya, x, clev, lab, s); This function will plot positive contours of x in solid lines, and negative contours of x in dashed lines. pncont(x) pncont's the matrix 'x'. pncont(xa, ya, x) uses xa and ya as the x and y axes resp. pncont(xa, ya, x, clev) uses levels outlined in 'clev', or if clev is an integer, uses clev levels. pncont(xa, ya, x, clev, lab) lab = 0 => don't label contours (default) lab = 1 => label contours pncont(xa, ya, x, clev, lab, s) s is a string containing the various plotting conventions. e.g. s = ['--k'] or whatever.
function [h, c] = pncont(xa, ya, x, clev, lab, s); %cla nexta = lower(get(gca, 'NextPlot')); nextf = lower(get(gcf, 'NextPlot')); hold_state = strcmp(nexta, 'add') & strcmp(nextf, 'add'); if ~hold_state; cla; end; lw = 1; if nargin == 1; x = xa; [m, n] = size(x); xa = 1:n; ya = 1:m; end; if nargin < 4; clev = 10; end; if nargin < 5; lab = 0; end; if nargin < 6; if nargin == 5 if isstr(lab); s = lab; lab = 0; else lab = s; s = []; end else s = []; end end if isscalar(clev); minx = min(min(x)); maxx = max(max(x)); cint = (maxx - minx + 2*eps) / clev; clev = (minx+eps):cint:(maxx+eps); end [m,n] = size(x); xp = eps * ones(m,n); xn = -1 * eps * ones(m,n); for i = 1:m; for j = 1:n; if x(i,j) <= 0; xp(i,j) = 0; xn(i,j) = x(i,j); else; xp(i,j) = x(i,j); xn(i,j) = 0; end; end; end; hold on h = []; c = []; if (max(max(x)) > clev(find(clev == min(clev(find(clev > 0)))))) [a, b] = contour(xa, ya, xp, clev(find(clev)), ['-' s]); if lab; clabel(a, b, 'manual'); end; set(b,'linewidth',lw); h = [b]; c = [a]; end; if (min(min(x)) < clev(find(clev == max(clev(find(clev < 0)))))); [cc, d] = contour(xa, ya, xn, clev(find(clev)), ['--' s]); if lab; clabel(c, d, 'manual'); end; set(d,'linewidth',lw); h = [h; d]; c = [c cc]; end; if (max(max(x)) > 0) & (min(min(x)) < 0 & ismember(0,clev) ) [e, f] = contour(xa, ya, x, [0 0], ['-' s]); if lab; clabel(e, f, 'manual'); end; set(f,'linewidth',2*lw); h = [h; f]; c = [c e]; end; hold off grid on;