/usr/share/freemat/toolbox/graph/contour.m is in freemat-data 4.0-5build1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 | % CONTOUR CONTOUR Contour Plot Function
%
% Usage
%
% This command generates contour plots. There are several syntaxes for
% the command. The simplest is
%
% contour(Z)
%
% which generates a contour plot of the data in matrix Z, and will
% automatically select the contour levels. The x,y coordinates of the
% contour default to 1:n and 1:m, where n is the number of
% columns and m is the number of rows in the Z matrix. Alternately,
% you can specify a scalar n
%
% contour(Z,n)
%
% which indicates that you want n contour levels. For more control,
% you can provide a vector v containing the levels to contour. If you
% want to generate a contour for a particular level, you must pass a
% vector [t,t] where t is the level you want to contour. If you
% have data that lies on a particular X,Y grid, you can pass either
% vectors x,y or matrices X,Y to the contour function via
%
% contour(X,Y,Z)
% contour(X,Y,Z,n)
% contour(X,Y,Z,v)
%
% Each form of contour can optionally take a line spec to indicate the
% color and linestyle of the contours to draw:
%
% contour(...,linespec)
%
% or any of the other forms of contour. Furthermore, you can supply an
% axis to target the contour plot to (so that it does not get added to
% the current axis, which is the default):
%
% contour(axis_handle,...)
%
% Finally, the contour command returns a handle to the newly returned
% contour plot.
%
% handle = contour(...)
%
% To place labels on the contour plot, use the clabel function.
% Copyright (c) 2002-2007 Samit Basu
% Licensed under the GPL
function ohandle = contour(varargin)
% Check for an axes handle
if (nargin>=2)
if (isnumeric(varargin{1}) && (length(varargin{1})==1) && ...
ishandle(varargin{1},'axes'))
handle = varargin{1}(1);
varargin(1) = [];
nargin = nargin - 1;
else
handle = newplot;
end
else
handle = newplot;
end
saveca = gca;
axes(handle);
% Have to decrypt the mode...
% strip off the linespec, if provided
color = []; marker = []; linetype = [];
linespec_given = islinespec(varargin{end},color,marker,linetype);
if (linespec_given)
varargin(end) = [];
nargin = nargin - 1;
end
if (nargin == 1)
h = hcontour('zdata',varargin{1});
elseif (nargin == 2)
if (numel(varargin{2}) == 1)
zdata = varargin{1};
zmin = min(zdata(:));
zmax = max(zdata(:));
h = hcontour('zdata',varargin{1},'levellist',...
linspace(zmin,zmax,varargin{2}));
else
h = hcontour('zdata',varargin{1},'levellist',varargin{2});
end
elseif (nargin == 3)
xdata = varargin{1};
ydata = varargin{2};
zdata = varargin{3};
h = hcontour('xdata',xdata,'ydata',ydata,'zdata',zdata);
elseif (nargin == 4)
xdata = varargin{1};
ydata = varargin{2};
zdata = varargin{3};
if (numel(varargin{4}) == 1)
zmin = min(zdata(:));
zmax = max(zdata(:));
h = hcontour('xdata',xdata,'ydata',ydata,'zdata',zdata,'levellist',...
linspace(zmin,zmax,varargin{4}));
else
h = hcontour('xdata',xdata,'ydata',ydata,'zdata',zdata, ...
'levellist',varargin{4});
end
end
if (linespec_given)
set(h,'linestyle',linetype,'linecolor',color);
end
axes(saveca);
if (nargout > 0)
ohandle = h;
end
function b = islinespec(t,&colorspec,&markerspec,&linespec)
% try to parse a string out as a linespec
% a linespec consists of three parts:
% a colorspec - y,m,c,r,g,b,w,k
% a markerspec - +o*.xs,square,s,diamond,d,^v><
% a linespec - -,--,:,-.
if (~isa(t,'char'))
b = 0;
return;
end
giveup = 0;
colorspec = 'none';
markerspec = 'none';
linespec = 'none';
orig_t = t;
while (~giveup && length(t)>0)
giveup = 1;
if (matchit(t,colorset))
colorspec = parseit(t,colorset);
giveup = 0;
end;
if (matchit(t,markerset))
markerspec = parseit(t,markerset);
giveup = 0;
end
if (matchit(t,styleset))
linespec = parseit(t,styleset);
giveup = 0;
end
end
if (giveup)
b = 0;
else
b = 1;
end
function b = matchit(t,dictionary)
b = any(stcmp(dictionary,t));
function b = parseit(&t,dictionary)
n = stcmp(dictionary,t);
b = dictionary{min(find(n))};
t(1:length(b)) = [];
function c = colorset
c = {'y','m','c','r','g','b','w','k'};
function c = styleset
c = {'--',':','-.','-'};
function c = markerset
c = {'+','o','*','.','x','square','s','diamond','d','^','v','>','<'};
function b = stcmp(source,pattern)
b = zeros(size(source),'logical');
for i=1:numel(source)
b(i) = strncmp(source{i},pattern,length(source{i}));
end
|