function contour( x, y, z, levels ) # contour (x,y,z,levels): plot contour lines of a function # # Plot contour lines by interpolating the values of a function # on a grid. If x,y,z are matrices with the same dimensions # the the corresponding elements represent points on the function. # levels contains a vector of heights at which to draw level curves, # or a scalar containing the number of equally spaced curves to # draw. # # If x is a vector and y is a vector, then z must be a matrix # with the same number of rows as x and the same number of # columns as y. The corresponding points are x(i),y(j),z(i,y) # are points of the function. if( nargin < 3 ) usage( "contour" ); return; endif if( nargin == 3 ) levels = 5; endif if( is_scalar( levels ) ) minz = min(min(z)); maxz = max(max(z)); diff = (maxz-minz)/(2*levels); levels = linspace(minz+diff,maxz-diff,levels ); endif if( !is_vector( levels )) error( "levels must be a vector or a scalar" ); endif if( is_vector(x) && is_vector(y)) if( length(x) != rows(z) || length(y) != columns(z) ) usage( "contour" ); return; endif [x,y] = meshgrid(x,y); endif if( rows(x) != rows(z) || rows(y) != rows(z) || columns(x) != columns(z) || columns(y) != columns(z) ) usage( "contour" ); return; endif __cntr__(x,y,z,levels); endfunction