% Installer: "snackbar_install.m" % Created: 30-Apr-2003 11:35:50. function bund_driver % bund_driver -- Driver for "bund" bundles. % bund_driver (no arguments) contains Matlab commands % to inflate the instructions and files that are % encoded into the "bund_data" function of this package. % Copyright (C) 2001 Dr. Charles R. Denham, ZYDECO. % All Rights Reserved. % Disclosure without explicit written consent from the % copyright owner does not constitute publication. % Version of 14-Jun-2001 10:54:16. % Updated 06-Feb-2003 14:36:58. help(mfilename) v = version; isVersion6 = (v(1) == '6'); BINARY_TAG = '?'; CR = char(13); LF = char(10); comp = upper(computer); if any(findstr(comp, 'PCWIN')) % Windows. NL = [CR LF]; elseif any(findstr(comp, 'MAC')) % Macintosh. NL = CR; else % Unix. NL = LF; end c = zeros(1, 256); c(abs('0'):abs('9')) = 0:9; c(abs('a'):abs('f')) = 10:15; disp([' ']) disp([' ## This installer is ready to expand its contents,']) disp([' ## starting in the present directory: "' pwd '"']) disp([' ## To abort, execute an interruption now.']) disp([' ## Otherwise, to continue, press any key.']) disp([' ']) try pause catch disp([' ## Installation interrupted.']) disp([' ']) return end % eval('pause', 'disp(''Installation interrupted.''), return') tic w = which(mfilename); fin = fopen(w, 'r'); if fin < 0, return, end found = ~~0; while ~found s = fgetl(fin); if isequal(s, -1) fclose(fin); return end s = strrep(s, LF, ''); % Not necessary? s = strrep(s, CR, ''); % Not necessary? if isequal(s, 'function bund_data') found = ~~1; end end fout = -1; done = ~~0; while ~done s = fgetl(fin); if isequal(s, -1) fclose(fin); return end s = strrep(s, LF, ''); % Not necessary? s = strrep(s, CR, ''); % Not necessary? if length(s) > 0 if s(1) ~= '%' f = findstr(s, 'bund_setdir'); if any(f) theDir = eval(strrep(s, 'bund_setdir', '')); [status, msg] = mkdir(theDir); switch status case 1 if isVersion6 & any(msg) disp([' ## Directory exists: "' theDir '"']) else disp([' ## Directory created: "' theDir '"']) end case 2 disp([' ## Directory exists: "' theDir '"']) otherwise error([' ## Error while making new directory.']) end try cd(theDir) catch error([' ## Unable to go to directory: "' theDir '"']) end % eval('cd(theDir)', ... % 'disp(theDir), error('' ## Unable to go to directory.'')') else % try % eval(s); % catch % error([' ## Unable to evaluate: "' s '"']) % end eval(s, ... 'disp(s), error(''Unable to evaluate statement.'')') end elseif length(s) > 1 & s(2) == BINARY_TAG hx = double(s(3:end)); % Assume hex data. bin = 16*c(hx(1:2:end)) + c(hx(2:2:end)); fwrite(fout, bin, 'uchar'); else fprintf(fout, '%s', s(2:end)); fprintf(fout, NL); end end end fclose(fin); disp([' ## Elapsed time: ' num2str(fix(10*toc)/10) ' s.']) function bund_data bund_setdir('snackbar') disp(' ## Installing: "end.m" (text)') fout = fopen('end.m', 'w'); %function theResult = end(self, k, n) % %% generic/end -- Evaluate "end" as an index. %% end(self, k, n) returns the value of "end" %% that has been used as the k-th index in %% a list of n indices, on behalf of "self", %% a "generic" object. % %% Copyright (C) 1999 Dr. Charles R. Denham, ZYDECO. %% All Rights Reserved. %% Disclosure without explicit written consent from the %% copyright owner does not constitute publication. % %% Version of 21-Apr-1999 08:50:46. % %if nargin < 1, help(mfilename), return, end % %s = size(self); % %if k == 1 & n == 1 % result = prod(s); %elseif k <= length(s) % result = s(k); %else % result = 0; %end % %if nargout > 0 % theResult = result; %else % disp(result) %end fclose(fout); disp(' ## Installing: "again.m" (text)') fout = fopen('again.m', 'w'); %function theResult = again(varargin) % %% again -- Button for "Again" actions. %% again('theCallback') adds an "Again" pushbutton %% to the current figure, to evaluate 'theCallback' %% when pressed. The button handle is returned. %% again('s1', 's2', ...) joins the string-arguments %% with blank-separators to form the actual %% callback. Use the words 'comma' and 'semicolon' %% to invoke those separators. %% h = again (no argument) returns the handle of %% the existing "Again" pushbutton. %% again('demo') demonstrates itself by plotting %% random numbers each time the button is pressed. %% %% Note: this code needs some work to prevent %% run-away recursions when it is called from %% another routine as part of a demo. % %% Copyright (C) 2000 Dr. Charles R. Denham, ZYDECO. %% All Rights Reserved. %% Disclosure without explicit written consent from the %% copyright owner does not constitute publication. % %% Version of 17-Feb-2000 23:41:04. %% Updated 21-Jun-2002 14:36:42. % %% Process the callback. % %if any(gcbo) % oldPointer = get(gcbf, 'Pointer'); % try % set(gcbf, 'Pointer', 'watch') % drawnow % eval(get(gcbo, 'Tag')) % catch % disp(' ') % disp('An error has occurred:') % disp(lasterr) % end % set(gcbf, 'Pointer', oldPointer) % return %end % %% Return the existing handle. % %props = {'Style', 'pushbutton', 'String', 'Again', ... % 'Position', [20 10 60 20]}; %h = findobj(gcf, props{:}); %if any(h) & nargin < 1 & nargout > 0 % theResult = h; % return %end % %% Create or update the button. % %if nargin < 1, varargin{1} = 'demo'; help(mfilename), end % %theCallback = ''; %for i = 1:length(varargin) % if i > 1, theCallback = [theCallback ' ']; end % switch varargin{i} % case {'then', 'comma'} % varargin{i} = ','; % case 'semicolon' % varargin{i} = ';'; % end % theCallback = [theCallback varargin{i}]; %end % %if isequal(theCallback, 'demo') % theCallback = 'n=ceil(50*rand(1,1))+1;plot(fft(eye(n,n)),''-o''),axis equal'; % eval(theCallback) %end % %if isempty(h) & ~isempty(theCallback) % h = uicontrol(props{:}); % set(h, 'Callback', mfilename, 'Tag', theCallback, ... % 'ToolTipString', theCallback) %elseif ~isempty(theCallback) % set(h, 'Callback', mfilename, 'Tag', theCallback, ... % 'ToolTipString', theCallback) %end % %figure(gcf) % %if nargout > 0, theResult = h; end fclose(fout); disp(' ## Installing: "allequal.m" (text)') fout = fopen('allequal.m', 'w'); %function theResult = allequal(x, varargin) % %% allequal -- Is first argument same as any other? %% allequal(x, var1, var2, ...) returns TRUE (~~1) %% if all the arguments are equal, in the sense %% of the NANEQUAL function; otherwise, it returns %% FALSE (~~0). %% %% Also see: ANYEQUAL, NANEQUAL. % %% Copyright (C) 2002 Dr. Charles R. Denham, ZYDECO. %% All Rights Reserved. %% Disclosure without explicit written consent from the %% copyright owner does not constitute publication. % %% Version of 20-Mar-2002 11:17:11. %% Updated 20-Mar-2002 11:17:11. % %if nargin < 2, help(mfilename), return, end % %result = ~~1; % %for i = 1:length(varargin) % if ~nanequal(x, varargin{i}) % result = ~~0; % break % end %end % %if nargout > 0 % theResult = result; %else % assignin('caller', 'ans', result) %end fclose(fout); disp(' ## Installing: "anyequal.m" (text)') fout = fopen('anyequal.m', 'w'); %function theResult = anyequal(x, varargin) % %% anyequal -- Is first argument same as any other? %% anyequal(x, var1, var2, ...) returns TRUE (~~1) %% if x is equal to any of the other arguments, %% in the sense of the NANEQUAL function; otherwise, %% it returns FALSE (~~0). %% %% Also see: ALLEQUAL, NANEQUAL. % %% Copyright (C) 2002 Dr. Charles R. Denham, ZYDECO. %% All Rights Reserved. %% Disclosure without explicit written consent from the %% copyright owner does not constitute publication. % %% Version of 20-Mar-2002 11:17:11. %% Updated 20-Mar-2002 11:17:11. % %if nargin < 2, help(mfilename), return, end % %result = ~~0; % %for i = 1:length(varargin) % if nanequal(x, varargin{i}) % result = ~~1; % break % end %end % %if nargout > 0 % theResult = result; %else % assignin('caller', 'ans', result) %end fclose(fout); disp(' ## Installing: "arrowsafe.m" (text)') fout = fopen('arrowsafe.m', 'w'); %function [x, y] = arrowsafe(x0, y0, theLength, theAngle, theHeadSize) % %% arrowsafe -- Intelligent, oriented arrows. %% arrowsafe('demo') demonstrates itself with arrows centered %% on the origin, each one-unit long. %% arrowsafe(N) demonstrates itself with N arrows. %% arrowsafe(x0, y0, theLength, theAngle, theHeadSize) draws %% arrows that start at (x0, y0), with theLength (in y-axis units), %% theAngle (degrees, counter-clockwise from +x), and theHeadSize %% (in y-axis units). The variables should be the same size, but %% any can be a scalar, just so long as the x0 and/or y0 array is %% the full size. The "ResizeFcn" of the figure is set to update %% the arrows automatically. The "Tag" is the mfilename. %% h = arrowsafe(...) draws the arrows and returns the handle. %% [x, y] = arrowsafe(...) returns the (x, y) data for the %% arrows, one column per arrow, but does not draw them. %% arrowsafe (no argument) redraws existing arrows. This is %% useful whenever the window is resized or the x or y limits %% change. (Recall that printing causes the "ResizeFcn" to %% be called twice.) %% %% Note: this routine leaves the axes in "manual" mode. Use %% "axis auto" to revert to automatic axis limits. % %% Copyright (C) 2000 Dr. Charles R. Denham, ZYDECO. %% All Rights Reserved. %% Disclosure without explicit written consent from the %% copyright owner does not constitute publication. % %% Version of 12-Jan-2000 14:22:59. %% Updated 20-Feb-2002 16:22:49. % %RCF = 180 / pi; % %% Resize. % %if nargin < 1 % oldGCA = gca; % h = findobj(gcf, 'Type', 'line', 'Tag', mfilename); % for i = 1:length(h) % p = get(h(i), 'Parent'); % axes(p) % u = get(h(i), 'UserData'); % [xx, yy] = feval(mfilename, u(:, 1), u(:, 2), ... % u(:, 3), u(:, 4), u(:, 5)); % set(h(i), 'XData', xx(:), 'YData', yy(:)); % end % axes(oldGCA) % return %end % %% Demonstration. % %if nargin == 1 % if isequal(x0, 'demo') % help(mfilename) % x0 = 16; % elseif ischar(x0) % x0 = eval(x0); % end % theName = [mfilename ' demo']; % f = findobj('Type', 'figure', 'Name', theName); % if ~any(f) % f = figure('Name', theName); % end % figure(max(f)) % delete(get(f, 'Children')) % n = max(1, round(x0)); % offset = 0; % x0 = zeros(1, n) + offset; % ang = linspace(0, 360, length(x0)+1); % ang(end) = []; % h = feval(mfilename, x0, 0, 1, ang); % set(gca, 'Xlim', [-n n], 'YLim', [-2 2]) % feval(mfilename) % set(gcf, 'WindowButtonDownFcn', ... % ['if zoomsafe(''down''), ' mfilename ', end']) % if nargout > 0, x = h; end % return %end % %% Initialize. % %if nargin > 1 % if nargout == 2, x = []; y = []; end % if length(x0) == 1 % x0 = x0 * ones(size(y0)); % elseif length(y0) == 1 % y0 = y0 * ones(size(x0)); % end % x0 = reshape(x0, [1 prod(size(x0))]); % y0 = reshape(y0, size(x0)); % if nargin < 3, theLength = 1; end % if nargin < 4, theAngle = 0; end % if nargin < 5, theHeadSize = 0.1 .* theLength; end % if length(theLength) == 1 % theLength = theLength * ones(size(x0)); % end % if length(theAngle) == 1 % theAngle = theAngle * ones(size(x0)); % end % if length(theHeadSize) == 1 % theHeadSize = theHeadSize * ones(size(x0)); % end % % theLength = reshape(theLength, size(x0)); % theAngle = reshape(theAngle, size(x0)); % theHeadSize = reshape(theHeadSize, size(x0)); % % axes(gca) % oldUnits = get(gca, 'Units'); % set(gca, 'Units', 'pixels') % thePosition = get(gca, 'Position'); % set(gca, 'Units', oldUnits) % theWidth = thePosition(3); % pixels. % theHeight = thePosition(4); % pixels. % % axis('manual') % dx = diff(get(gca, 'XLim')); % dy = diff(get(gca, 'YLim')); % dydx = dy / dx; % Not used. % dxdp = dx / theWidth; % sci/pixel. % dydp = dy / theHeight; % sci/pixel. % scale = dxdp / dydp; %% <== Scale-factor. % % xa = [-10; -20; 0; -20; -10]/20; % Arrowhead. % ya = [0; 10; 0; -10; 0]/20; % % m = length(xa); % n = prod(size(x0)); % repeats = [m 1]; % % ang = repmat(theAngle, repeats); % len = repmat(theLength, repeats); % head = repmat(theHeadSize, repeats); % % xa = repmat(xa, [1 n]); % ya = repmat(ya, [1 n]); % % xa = xa .* head; % ya = ya .* head; % % xa = xa + len; % % za = xa + sqrt(-1) * ya; % % za = [zeros(1, n); za]; % % ang = repmat(theAngle, [size(za, 1) 1]); % len = repmat(theLength, [size(za, 1) 1]); % head = repmat(theHeadSize, [size(za, 1) 1]); % xx0 = repmat(x0, [size(za, 1) 1]); % yy0 = repmat(y0, [size(za, 1) 1]); % % za = exp(sqrt(-1) * ang / RCF) .* za; % xx = real(za); % yy = imag(za); % % nans = zeros(1, n) + NaN; % % xx = [xx; nans]; % yy = [yy; nans]; % % zz = xx + sqrt(-1) .* yy; % % xx0 = repmat(x0, [size(zz, 1) 1]); % yy0 = repmat(y0, [size(zz, 1) 1]); % % xx = xx0 + real(zz) * scale; % <== Scaling. % yy = yy0 + imag(zz); % % parameters = [x0(:) y0(:) theLength(:) theAngle(:) theHeadSize(:)]; % % if nargout < 2 % h = line(xx(:), yy(:), ... % 'Tag', mfilename, ... % 'UserData', parameters); % if nargout > 1, x = h; end % elseif nargout == 2 % x = xx; % y = yy; % end % set(gcf, 'ResizeFcn', mfilename) % % if nargout == 1, x = h; end %end fclose(fout); disp(' ## Installing: "ascii.m" (text)') fout = fopen('ascii.m', 'w'); %function ascii % %% ascii -- Display Ascii Character Table. %% ascii (no argument) displays the Ascii Character Table %% in the current font. % %% Copyright (C) 1997 Dr. Charles R. Denham, ZYDECO. %% All Rights Reserved. %% Disclosure without explicit written consent from the %% copyright owner does not constitute publication. % %% Version of 17-Sep-1997 16:21:23. % %a = zeros(256, 4) + abs(' '); %a(:, 4) = (0:255).'; %a = setstr(a); % %% Control characters. % %a( 0+1, 2:4) = 'NUL'; %a( 1+1, 2:4) = 'SOH'; %a( 2+1, 2:4) = 'STX'; %a( 3+1, 2:4) = 'ETX'; %a( 4+1, 2:4) = 'EOT'; %a( 5+1, 2:4) = 'ENQ'; %a( 6+1, 2:4) = 'ACK'; %a( 7+1, 2:4) = 'BEL'; %a( 8+1, 2:4) = ' BS'; %a( 9+1, 2:4) = ' HT'; %a( 10+1, 2:4) = ' LF'; %a( 11+1, 2:4) = ' VT'; %a( 12+1, 2:4) = ' FF'; %a( 13+1, 2:4) = ' CR'; %a( 14+1, 2:4) = ' SO'; %a( 15+1, 2:4) = ' SI'; %a( 16+1, 2:4) = 'DLE'; %a( 17+1, 2:4) = 'DC1'; %a( 18+1, 2:4) = 'DC2'; %a( 19+1, 2:4) = 'DC3'; %a( 20+1, 2:4) = 'DC4'; %a( 21+1, 2:4) = 'NAK'; %a( 22+1, 2:4) = 'SYN'; %a( 23+1, 2:4) = 'ETB'; %a( 24+1, 2:4) = 'CAN'; %a( 25+1, 2:4) = ' EM'; %a( 26+1, 2:4) = 'SUB'; %a( 27+1, 2:4) = 'ESC'; %a( 28+1, 2:4) = ' FS'; %a( 29+1, 2:4) = ' GS'; %a( 30+1, 2:4) = ' RS'; %a( 31+1, 2:4) = ' US'; % %% Other named characters. % %a( 32+1, 2:4) = ' SP'; %a(127+1, 2:4) = 'DEL'; % %% Reshape. % %a = reshape(a.', prod(size(a))/16, 16).'; % %% Display. % %disp(' ') %disp(' ## Ascii Character Table') %disp(' ') %disp(a) %disp(' ') fclose(fout); disp(' ## Installing: "assign.m" (text)') fout = fopen('assign.m', 'w'); %function assign(theName, theValue) % %% assign -- Assign a value to a name. %% assign('theName', theValue) assigns theValue %% to 'theName' in the caller's workspace. It %% avoids the need to construct an explicit %% assignment statement to be eval-ed. % %% Copyright (C) 1997 Dr. Charles R. Denham, ZYDECO. %% All Rights Reserved. %% Disclosure without explicit written consent from the %% copyright owner does not constitute publication. % %% Version of 28-May-1998 00:43:58. % %if nargin < 2, help(mfilename), return, end % %% The following scheme permits the assignment %% of items that have complicated subscripts, %% such as "a{1}(2).b{3}.c = pi". % %hasAns = (evalin('caller', 'exist(''ans'', ''var'')') == 1); %if hasAns % ans = evalin('caller', 'ans'); % Save. %end %assignin('caller', 'ans', theValue) %evalin('caller', [theName ' = ans;']) %evalin('caller', 'clear(''ans'')') %if hasAns % assignin('caller', 'ans', ans) % Restore. %end fclose(fout); disp(' ## Installing: "at.m" (text)') fout = fopen('at.m', 'w'); %function theResult = at(theFile, theOffset) % %% at -- Switch to the folder of a given file. %% at('theFunction') switches to the folder of %% 'theFunction', as determined by the "which" %% function. %% at('theFunction', theOffset) performs as above, %% then marches into higher directories by the %% amount of theOffset, which must be a negative %% integer. % %% Copyright (C) 2000 Dr. Charles R. Denham, ZYDECO. %% All Rights Reserved. %% Disclosure without explicit written consent from the %% copyright owner does not constitute publication. % %% Version of 01-Feb-2000 22:21:09. %% Updated 22-Apr-2003 09:19:37. % %if nargout > 0, theResult = []; end % %if nargin < 1, help(mfilename), return, end %if nargin < 2, theOffset = 0; end %if ischar(theOffset), theOffset = eval(theOffset); end % %w = which(theFile); % %if isempty(w) % w = which([theFile '/' theFile]); % if isempty(w) % disp([' ## No such file: ' theFile]) % return % end %elseif isequal(w, 'built-in') % disp([' ## ' theFile ' is built-in. Try "at ' theFile '.m".']) % return %end % %[thePath, theName, theExtension, theVersion] = fileparts(w); % %if any(thePath) % cd(thePath) % if theOffset < 0 % for i = 1:fix(abs(theOffset)) % cd .. % end % end %end % %if nargout > 0 % theResult = pwd; %else % disp([' ## ' pwd]) %end fclose(fout); disp(' ## Installing: "basic_english.m" (text)') fout = fopen('basic_english.m', 'w'); %function theWordList = basic_english % %% basic_english (no argument) returns the alphabetized %% "Basic English" word-list of Charles Kay Ogden, from %% the Basic English web-site "http://www.basiceng.com". %% The result is a cell-array of 850 words. % %% Copyright (C) 2002 Dr. Charles R. Denham, ZYDECO. %% All Rights Reserved. %% Disclosure without explicit written consent from the %% copyright owner does not constitute publication. % %% Version of 08-Mar-2002 11:56:44. %% Updated 08-Mar-2002 12:03:40. % %% Original Ogden sequence. % %wordlist = { % %'come' 'get' 'give' 'go' 'keep' 'let' 'make' 'put' 'seem' 'take' % 'be' 'do' 'have' 'say' 'see' 'send' 'may' 'will' 'about' 'across' % 'after' 'against' 'among' 'at' 'before' 'between' 'by' 'down' 'from' 'in' % 'off' 'on' 'over' 'through' 'to' 'under' 'up' 'with' 'as' 'for' % 'of' 'till' 'than' 'a' 'the' 'all' 'any' 'every' 'no' 'other' % 'some' 'such' 'that' 'this' 'I' 'he' 'you' 'who' 'and' 'because' % 'but' 'or' 'if' 'though' 'while' 'how' 'when' 'where' 'why' 'again' % 'ever' 'far' 'forward' 'here' 'near' 'now' 'out' 'still' 'then' 'there' % 'together' 'well' 'almost' 'enough' 'even' 'little' 'much' 'not' 'only' 'quite' % 'so' 'very' 'tomorrow' 'yesterday' 'north' 'south' 'east' 'west' 'please' 'yes' % 'account' 'act' 'addition' 'adjustment' 'advertisement' 'agreement' 'air' 'amount' 'amusement' 'animal' % 'answer' 'apparatus' 'approval' 'argument' 'art' 'attack' 'attempt' 'attention' 'attraction' 'authority' % 'back' 'balance' 'base' 'behavior' 'belief' 'birth' 'bit' 'bite' 'blood' 'blow' % 'body' 'brass' 'bread' 'breath' 'brother' 'building' 'burn' 'burst' 'business' 'butter' % 'canvas' 'care' 'cause' 'chalk' 'chance' 'change' 'cloth' 'coal' 'color' 'comfort' % 'committee' 'company' 'comparison' 'competition' 'condition' 'connection' 'control' 'cook' 'copper' 'copy' % 'cork' 'cotton' 'cough' 'country' 'cover' 'crack' 'credit' 'crime' 'crush' 'cry' % 'current' 'curve' 'damage' 'danger' 'daughter' 'day' 'death' 'debt' 'decision' 'degree' % 'design' 'desire' 'destruction' 'detail' 'development' 'digestion' 'direction' 'discovery' 'discussion' 'disease' % 'disgust' 'distance' 'distribution' 'division' 'doubt' 'drink' 'driving' 'dust' 'earth' 'edge' % 'education' 'effect' 'end' 'error' 'event' 'example' 'exchange' 'existence' 'expansion' 'experience' % 'expert' 'fact' 'fall' 'family' 'father' 'fear' 'feeling' 'fiction' 'field' 'fight' % 'fire' 'flame' 'flight' 'flower' 'fold' 'food' 'force' 'form' 'friend' 'front' % 'fruit' 'glass' 'gold' 'government' 'grain' 'grass' 'grip' 'group' 'growth' 'guide' % 'harbor' 'harmony' 'hate' 'hearing' 'heat' 'help' 'history' 'hole' 'hope' 'hour' % 'humor' 'ice' 'idea' 'impulse' 'increase' 'industry' 'ink' 'insect' 'instrument' 'insurance' % 'interest' 'invention' 'iron' 'jelly' 'join' 'journey' 'judge' 'jump' 'kick' 'kiss' % 'knowledge' 'land' 'language' 'laugh' 'law' 'lead' 'learning' 'leather' 'letter' 'level' % 'lift' 'light' 'limit' 'linen' 'liquid' 'list' 'look' 'loss' 'love' 'machine' % 'man' 'manager' 'mark' 'market' 'mass' 'meal' 'measure' 'meat' 'meeting' 'memory' % 'metal' 'middle' 'milk' 'mind' 'mine' 'minute' 'mist' 'money' 'month' 'morning' % 'mother' 'motion' 'mountain' 'move' 'music' 'name' 'nation' 'need' 'news' 'night' % 'noise' 'note' 'number' 'observation' 'offer' 'oil' 'operation' 'opinion' 'order' 'organization' % 'ornament' 'owner' 'page' 'pain' 'paint' 'paper' 'part' 'paste' 'payment' 'peace' % 'person' 'place' 'plant' 'play' 'pleasure' 'point' 'poison' 'polish' 'porter' 'position' % 'powder' 'power' 'price' 'print' 'process' 'produce' 'profit' 'property' 'prose' 'protest' % 'pull' 'punishment' 'purpose' 'push' 'quality' 'question' 'rain' 'range' 'rate' 'ray' % 'reaction' 'reading' 'reason' 'record' 'regret' 'relation' 'religion' 'representative' 'request' 'respect' % 'rest' 'reward' 'rhythm' 'rice' 'river' 'road' 'roll' 'room' 'rub' 'rule' % 'run' 'salt' 'sand' 'scale' 'science' 'sea' 'seat' 'secretary' 'selection' 'self' % 'sense' 'servant' 'sex' 'shade' 'shake' 'shame' 'shock' 'side' 'sign' 'silk' % 'silver' 'sister' 'size' 'sky' 'sleep' 'slip' 'slope' 'smash' 'smell' 'smile' % 'smoke' 'sneeze' 'snow' 'soap' 'society' 'son' 'song' 'sort' 'sound' 'soup' % 'space' 'stage' 'start' 'statement' 'steam' 'steel' 'step' 'stitch' 'stone' 'stop' % 'story' 'stretch' 'structure' 'substance' 'sugar' 'suggestion' 'summer' 'support' 'surprise' 'swim' % 'system' 'talk' 'taste' 'tax' 'teaching' 'tendency' 'test' 'theory' 'thing' 'thought' % 'thunder' 'time' 'tin' 'top' 'touch' 'trade' 'transport' 'trick' 'trouble' 'turn' % 'twist' 'unit' 'use' 'value' 'verse' 'vessel' 'view' 'voice' 'walk' 'war' % 'wash' 'waste' 'water' 'wave' 'wax' 'way' 'weather' 'week' 'weight' 'wind' % 'wine' 'winter' 'woman' 'wood' 'wool' 'word' 'work' 'wound' 'writing' 'year' % 'angle' 'ant' 'apple' 'arch' 'arm' 'army' 'baby' 'bag' 'ball' 'band' % 'basin' 'basket' 'bath' 'bed' 'bee' 'bell' 'berry' 'bird' 'blade' 'board' % 'boat' 'bone' 'book' 'boot' 'bottle' 'box' 'boy' 'brain' 'brake' 'branch' % 'brick' 'bridge' 'brush' 'bucket' 'bulb' 'button' 'cake' 'camera' 'card' 'cart' % 'carriage' 'cat' 'chain' 'cheese' 'chest' 'chin' 'church' 'circle' 'clock' 'cloud' % 'coat' 'collar' 'comb' 'cord' 'cow' 'cup' 'curtain' 'cushion' 'dog' 'door' % 'drain' 'drawer' 'dress' 'drop' 'ear' 'egg' 'engine' 'eye' 'face' 'farm' % 'feather' 'finger' 'fish' 'flag' 'floor' 'fly' 'foot' 'fork' 'fowl' 'frame' % 'garden' 'girl' 'glove' 'goat' 'gun' 'hair' 'hammer' 'hand' 'hat' 'head' % 'heart' 'hook' 'horn' 'horse' 'hospital' 'house' 'island' 'jewel' 'kettle' 'key' % 'knee' 'knife' 'knot' 'leaf' 'leg' 'library' 'line' 'lip' 'lock' 'map' % 'match' 'monkey' 'moon' 'mouth' 'muscle' 'nail' 'neck' 'needle' 'nerve' 'net' % 'nose' 'nut' 'office' 'orange' 'oven' 'parcel' 'pen' 'pencil' 'picture' 'pig' % 'pin' 'pipe' 'plane' 'plate' 'plough/plow' 'pocket' 'pot' 'potato' 'prison' 'pump' % 'rail' 'rat' 'receipt' 'ring' 'rod' 'roof' 'root' 'sail' 'school' 'scissors' % 'screw' 'seed' 'sheep' 'shelf' 'ship' 'shirt' 'shoe' 'skin' 'skirt' 'snake' % 'sock' 'spade' 'sponge' 'spoon' 'spring' 'square' 'stamp' 'star' 'station' 'stem' % 'stick' 'stocking' 'stomach' 'store' 'street' 'sun' 'table' 'tail' 'thread' 'throat' % 'thumb' 'ticket' 'toe' 'tongue' 'tooth' 'town' 'train' 'tray' 'tree' 'trousers' % 'umbrella' 'wall' 'watch' 'wheel' 'whip' 'whistle' 'window' 'wing' 'wire' 'worm' % 'able' 'acid' 'angry' 'automatic' 'beautiful' 'black' 'boiling' 'bright' 'broken' 'brown' % 'cheap' 'chemical' 'chief' 'clean' 'clear' 'common' 'complex' 'conscious' 'cut' 'deep' % 'dependent' 'early' 'elastic' 'electric' 'equal' 'fat' 'fertile' 'first' 'fixed' 'flat' % 'free' 'frequent' 'full' 'general' 'good' 'great' 'grey/gray' 'hanging' 'happy' 'hard' % 'healthy' 'high' 'hollow' 'important' 'kind' 'like' 'living' 'long' 'male' 'married' % 'material' 'medical' 'military' 'natural' 'necessary' 'new' 'normal' 'open' 'parallel' 'past' % 'physical' 'political' 'poor' 'possible' 'present' 'private' 'probable' 'quick' 'quiet' 'ready' % 'red' 'regular' 'responsible' 'right' 'round' 'same' 'second' 'separate' 'serious' 'sharp' % 'smooth' 'sticky' 'stiff' 'straight' 'strong' 'sudden' 'sweet' 'tall' 'thick' 'tight' % 'tired' 'true' 'violent' 'waiting' 'warm' 'wet' 'wide' 'wise' 'yellow' 'young' % 'awake' 'bad' 'bent' 'bitter' 'blue' 'certain' 'cold' 'complete' 'cruel' 'dark' % 'dead' 'dear' 'delicate' 'different' 'dirty' 'dry' 'false' 'feeble' 'female' 'foolish' % 'future' 'green' 'ill' 'last' 'late' 'left' 'loose' 'loud' 'low' 'mixed' % 'narrow' 'old' 'opposite' 'public' 'rough' 'sad' 'safe' 'secret' 'short' 'shut' % 'simple' 'slow' 'small' 'soft' 'solid' 'special' 'strange' 'thin' 'white' 'wrong' %}; % %wordlist = sort(wordlist(:)); % %if nargout > 0 % theWordList = wordlist; %else % assignin('caller', 'ans', wordlist) %end fclose(fout); disp(' ## Installing: "begets.m" (text)') fout = fopen('begets.m', 'w'); %function msg = Begets(fcn,nin,a,b,c,d,e,f,g,h,i,j) % %% Begets -- Message showing the result of a function. %% Begets('fcn',nin,a,b,...) creates a message that %% shows the function 'fcn' with its input and %% output values. The number of input arguments %% is nin. The argument list a,b,... is organized %% into nin input values, followed immediately by %% the output values. Thus, begets('sqrt', 1, 4, 2) %% results in the message "sqrt(4) ==> 2". % %% Uses: var2str. % %% Copyright (C) 1991 Charles R. Denham, ZYDECO. %% All Rights Reserved. % %if nargin < 1 % help(mfilename) % disp(' Some examples:') % x = (1:4).'; % begets('mean', 1, x, mean(x)); % x = (2:4).^2; % begets('sqrt', 1, x, sqrt(x)); % x = [1 2; 3 4]; [m, n] = size(x); % begets('size', 1, x, [m n]); % begets('size', 1, x, m, n); % x = [1 2; 2 1]; [v, d] = eig(x); % begets('eig', 1, x, v, d) % begets('1/0', 0, inf) % begets('inf.*0', 0, inf.*0) % x = abs('hello'); % begets('setstr', 1, x, setstr(x)) % x = 'hello'; % begets('abs', 1, x, abs(x)) % return %end % %% FCN(...) Input argument list. % %s = ''; %s = [fcn]; %if nin > 0, s = [s '(']; end %arg = 'a'; %for ii = 1:nin; % s = [s var2str(eval(arg))]; % if ii < nin, s = [s ', ']; end % arg = setstr(arg + 1); %end %if nin > 0, s = [s ')']; end % %% [...] Output argument list. % %t = ''; %nout = nargin - nin - 2; %if nout > 1, t = ['[']; end %for ii = 1:nout % t = [t var2str(eval(arg))]; % if ii < nout, t = [t ', ']; end % arg = setstr(arg + 1); %end %if nout > 1, t = [t ']']; end % %% Message. % %% u = [t ' = ' s]; %u = [s ' ==> ' t]; % %if nargout > 0, msg = u; else, disp([' ' u]); end fclose(fout); disp(' ## Installing: "bgtext.m" (text)') fout = fopen('bgtext.m', 'w'); %function handle = bgtext(x, y, z, string, color, varargin) % %% bgtext -- Text with background color. %% bgtext(x, y, 'string', color, ...) draws the text with %% the given patch color in the background. The "ResizeFcn" %% of the figure is set to resize the patches automatically. %% The default color is light-gray. Except for the added %% "color" argument, the syntax is the same as for "text". %% bgtext(x, y, z, 'string', color, ...) for 3-d text position. %% bgtext(theFigure) resizes the background patches to fit the %% extents of the "bgtext" objects in theFigure (default = gcf). %% bgtext('demo', N) demonstrates itself for N random locations %% (default = 2), in a random color. % %% Copyright (C) 1999 Dr. Charles R. Denham, ZYDECO. %% All Rights Reserved. %% Disclosure without explicit written consent from the %% copyright owner does not constitute publication. % %% Version of 26-Aug-1999 14:26:10. %% Updated 31-Aug-1999 16:23:27. % %DEFAULT_COLOR = [9 9 9]/10; % %if nargin < 1, x = gcf; end % %% Demonstration. % %if isequal(x, 'demo') % n = 2; % if nargin > 1 % if isstr(y), y = eval(y); end % n = y; % end % x = rand(n, 1); % y = rand(size(x)); % string = 'Hello World'; % color = 0.5 * (1 + rand(1, 3)); % color = color / max(color); % set(gca, 'XLim', [-0.5 1.5], 'YLim', [-0.5 1.5]) % bgtext(x, y, string, color) % set(gcf, 'Name', [mfilename ' demo']) % zoomsafe % figure(gcf) % return %end % %% Resize background patch sizes. % %if nargin < 2 & ishandle(x) & isequal(get(x, 'Type'), 'figure') % h = x; % f = findobj(h, 'Type', 'text', 'Tag', mfilename); % for i = 1:length(f) % t = f(i); % p = get(t, 'UserData'); % ax = get(t, 'Parent'); % xdir = get(ax, 'XDir'); % ydir = get(ax, 'YDir'); % if ishandle(p) % switch get(p, 'Type') % case 'patch' % extent = get(t, 'Extent'); % x0 = extent(1); y0 = extent(2); % width = extent(3); height = extent(4); % xp = x0 + [0 width width 0]; % yp = y0 + [0 0 height height]; % switch xdir % case 'reverse' % xp = xp - (max(xp) - min(xp)); % otherwise % end % switch ydir % case 'reverse' % yp = yp - (max(yp) - min(yp)); % otherwise % end % set(p, 'XData', xp, 'YData', yp) % otherwise % end % end % end % return %end % %% Normal processing. % %is3d = ~isstr(z); % %if ~is3d % if nargin > 4 % varargin = [{color} varargin]; % else % varargin = {}; % end % if nargin > 3 % color = string; % else % color = DEFAULT_COLOR; % end % string = z; %else % if nargin < 5 % color = DEFAULT_COLOR; % end %end % %wasHold = ishold; %hold on % %% Measure temporary text (invisible). % %if ~is3d % t = text(x, y, string); %else % t = text(x, y, z, string); %end % %ax = get(t(1), 'Parent'); %xdir = get(ax, 'XDir'); %ydir = get(ax, 'YDir'); % %if ~isempty(varargin), set(t, varargin{:}), end %set(t, 'Visible', 'off') % %extent = zeros(length(t), 4); %for i = 1:length(t) % extent(i, :) = get(t(i), 'Extent'); %end % %% Delete temporary text. % %delete(t) % %% Create patches. % %p = zeros(length(t), 1); %for i = 1:length(t) % x0 = extent(i, 1); y0 = extent(i, 2); % width = extent(i, 3); height = extent(i, 4); % xp = x0 + [0 width width 0]; % yp = y0 + [0 0 height height]; % switch xdir % case 'reverse' % xp = xp - (max(xp) - min(xp)); % otherwise % end % switch ydir % case 'reverse' % yp = yp - (max(yp) - min(yp)); % otherwise % end % p(i) = patch(xp, yp, color); %end %set(p, 'EdgeColor', 'none', 'Tag', mfilename) % %% Superimpose new text. % %if ~is3d % t = text(x, y, string); %else % t = text(x, y, z, string); %end % %if ~wasHold, hold off, end % %if ~isempty(varargin), set(t, varargin{:}), end % %for i = 1:length(t) % set(t(i), 'UserData', p(i), 'Tag', mfilename) %end % %% Set the "ResizeFcn" callback. % %set(gcf, 'ResizeFcn', [mfilename]) % %% Return. % %if nargout > 0, handle = t; end fclose(fout); disp(' ## Installing: "blinksafe.m" (text)') fout = fopen('blinksafe.m', 'w'); %function vis = blinksafe(varargin) % %% blinksafe -- Toggle data points in (x, y, z) plot. %% blinksafe('demo') demonstrates itself, using random (x, y) %% data plotted with EraseMode = 'xor'. %% blinksafe('on') enables blinking, in which a mouse click %% on a plotted (x, y, z) point makes the point invisible %% and marks the site with a distinctive dot. The z-value %% at that point is set to NaN, and its original value is %% remembered for later restoration. The proximity of the %% click to a point is determined in the (x, y) plane only. %% blinksafe(h) turns blinking on for just the lines specified %% by the handles h. %% blinksafe('off') turns blinking off and removes the markers. %% Points invisible at this stage will remain invisible, %% since the corresponding z values will now be NaN. %% blinksafe('clear') restores all the plotted data to visibility. %% vis = blinksafe(h) returns the visibility-vector (1 = visible; %% 0 = not visible) for the line whose handle is h. %% %% Also see: marksafe. % %% Copyright (C) 2000 Dr. Charles R. Denham, ZYDECO. %% All Rights Reserved. %% Disclosure without explicit written consent from the %% copyright owner does not constitute publication. % %% Version of 12-Jan-2000 09:44:58. %% Updated 02-Feb-2000 23:45:50. % %BLINKER_TAG = ['_' mfilename '_']; %BLINKER_MARKER = '*'; %BLINKER_SIZE = get(0, 'DefaultLineMarkerSize'); %BLINKER_COLOR = [1 0 0]; %BLINKER_BUTTONDOWNFCN = mfilename; % %% Demonstration. % %if nargin > 0 & isequal(varargin{1}, 'demo') % help(mfilename) % x = linspace(0, 1, 101); % y = sin(3*pi*x); % noise = 2*(rand(size(x)) - 0.5); % noise(abs(noise) < 0.95) = 0; % h = plot(x, y+noise, '-o', ... % 'MarkerSize', 4, 'EraseMode', 'xor'); % eval(mfilename) % if exist('zoomsafe', 'file') == 2 % eval('zoomsafe') % end % set(gcf, 'Name', [mfilename ' demo']) % if nargout > 0, vis = h; end % return %end % %% Get visibility of a line. %% Requires a handle and an output variable. % %if nargout > 0 & nargin > 0 % vis = []; % h = varargin{1}; % if ischar(h), h = eval(h); end % if ishandle(h) % if isequal(get(h, 'Type'), 'line') % if ~isequal(get(h, 'Tag'), BLINKER_TAG) % vis = isfinite(get(h, 'ZData')); % end % end % end % return %end % %% Actions: on, off, clear. % %if nargin > 0 & isempty(gcbo) % if ischar(varargin{1}) % theAction = varargin{1}; % switch theAction % case 'on' % varargin = {}; % case 'off' % h = findobj(gcf, 'Tag', BLINKER_TAG); % if any(h), delete(h), end % return % case 'clear' % h = findobj(gcf, 'Tag', BLINKER_TAG); % if any(h) % for i = 1:length(h) % u = get(h(i), 'UserData'); % z = get(u.handle, 'ZData'); % z(u.index) = u.z; % set(u.handle, 'ZData', z) % end % delete(h) % end % return % otherwise % disp([' ## No such action: "' theAction '"']) % return % end % end %end % %% Initialize. % %if isempty(gcbo) % if isempty(varargin) % h = findobj(gcf, 'Type', 'line'); % varargin{1} = h; % end % h = varargin{1}; % set(h, 'ButtonDownFcn', BLINKER_BUTTONDOWNFCN) % for i = 1:length(h) % z = get(h(i), 'ZData'); % if isempty(z) % x = get(h(i), 'XData'); % z = zeros(size(x)); % set(h(i), 'ZData', z); % end % end % return %end % %% Process a click. If clicking on the data, make %% the closest data point invisible. If clicking %% on a "blinker", restore the visibility of the %% corresponding point. % %if isempty(varargin), varargin{1} = 'ButtonDownFcn'; end % %if length(varargin) > 0 & ischar(varargin{1}) % theEvent = varargin{1}; % switch lower(theEvent) % case 'buttondownfcn' % switch get(gcbo, 'Tag') % case '_blinksafe_' % Restore visibility; delete the blinker. % u = get(gcbo, 'UserData'); % z = get(u.handle, 'ZData'); % z(u.index) = u.z; % set(u.handle, 'ZData', z); % delete(gcbo) % otherwise % Make invisible; create a blinker. % p = get(gca, 'CurrentPoint'); % x0 = p(1, 1); % y0 = p(1, 2); % x = get(gcbo, 'XData'); % y = get(gcbo, 'YData'); % % dx = diff(get(gca, 'XLim')); % Scale to pixels. % dy = diff(get(gca, 'YLim')); % theOldUnits = get(gca, 'Units'); % set(gca, 'Units', 'pixels'); % thePosition = get(gca, 'Position'); % theWidth = thePosition(3); % theHeight = thePosition(4); % dx = dx / theWidth; % dy = dy / theHeight; % set(gca, 'Units', theOldUnits) % % d = abs((x*dy+sqrt(-1)*y*dx - (x0*dy+sqrt(-1)*y0*dx))); % % index = find(d == min(d)); % if any(index) % index = index(1); % z = get(gcbo, 'ZData'); % if isempty(z), z = zeros(size(x)); end % if isfinite(z(index)) & 0 % u.handle = gcbo; % u.index = index; % u.z = z(index); % theMarker = get(gcbo, 'Marker'); % if isequal(theMarker, BLINKER_MARKER) % BLINKER_MARKER = 'o'; % end % h = line(x(index), y(index),... % 'Marker', BLINKER_MARKER, ... % 'MarkerSize', BLINKER_SIZE, ... % 'MarkerFaceColor', 'none', ... % 'MarkerEdgeColor', BLINKER_COLOR, ... % 'EraseMode', 'xor', ... % 'ButtonDownFcn', BLINKER_BUTTONDOWNFCN, ... % 'UserData', u, ... % 'Tag', BLINKER_TAG); % z(index) = nan; % set(gcbo, 'ZData', z) % else % h = make_blinker(gcbo, index); % end % end % end % otherwise % disp(['## No such event: ' theEvent]) % end %end % %% ---------- make_blinker ---------- % % %function theResult = make_blinker(h, index) % %% make_blinker -- Create a blinker. %% make_blinker(h, index) places a blinker %% on line h at the given index. % %% Copyright (C) 2000 Dr. Charles R. Denham, ZYDECO. %% All Rights Reserved. %% Disclosure without explicit written consent from the %% copyright owner does not constitute publication. % %% Version of 18-Jan-2000 14:11:55. %% Updated 18-Jan-2000 14:11:55. % %BLINKER_TAG = ['_' mfilename '_']; %BLINKER_MARKER = '*'; %BLINKER_SIZE = get(0, 'DefaultLineMarkerSize'); %BLINKER_COLOR = [1 0 0]; %BLINKER_BUTTONDOWNFCN = mfilename; % %result = zeros(size(h)); % %for i = 1:length(h) % x = get(h(i), 'XData'); % y = get(h(i), 'YData'); % z = get(h(i), 'ZData'); % if isempty(z) % z = zeros(size(x)); % end % theMarker = get(h(i), 'Marker'); % if isequal(theMarker, BLINKER_MARKER) % BLINKER_MARKER = 'o'; % end % if ~isequal(get(gcbo, 'Marker'), 'none') % BLINKER_SIZE = 2 + get(gcbo, 'MarkerSize'); % end % % if isfinite(z(index)) % u.handle = h(i); % u.index = index; % u.z = z(index); % result(i) = line(x(index), y(index),... % 'Marker', BLINKER_MARKER, ... % 'MarkerSize', BLINKER_SIZE, ... % 'MarkerFaceColor', 'none', ... % 'MarkerEdgeColor', BLINKER_COLOR, ... % 'EraseMode', 'xor', ... % 'ButtonDownFcn', BLINKER_BUTTONDOWNFCN, ... % 'UserData', u, ... % 'Tag', BLINKER_TAG); % z(index) = nan; % set(h(i), 'ZData', z) % end %end % %if nargout > 0, theResult = result; end fclose(fout); disp(' ## Installing: "bringtofront.m" (text)') fout = fopen('bringtofront.m', 'w'); %function bringtofront(varargin) % %% bringtofront -- Lift graphical objects. %% bringtofront(theHandles, ...) brings theHandles %% to the front, one-by-one, in the order listed. %% Any number of handles can be mentioned, either %% as matrices or scalars. % %% Copyright (C) 1999 Dr. Charles R. Denham, ZYDECO. %% All Rights Reserved. %% Disclosure without explicit written consent from the %% copyright owner does not constitute publication. % %% Version of 15-Apr-1999 19:40:12. %% Updated 12-Mar-2002 12:09:59. % %if nargin < 1, help(mfilename), return, end % %for j = 1:prod(size(varargin)) % theHandles = varargin{j}; % if ischar(theHandles), theHandles = evalin('caller', theHandles); end % for i = 1:prod(size(theHandles)) % if ishandle(theHandles(i)) % theType = get(theHandles(i), 'Type'); % theParent = get(theHandles(i), 'Parent'); % theParentType = get(theParent, 'Type'); % theChildren = get(theParent, 'Children'); % theChildren(theChildren == theHandles(i)) = []; % theChildren = [theHandles(i); theChildren(:)]; % set(theParent, 'Children', theChildren) % switch theType % case {'figure', 'axes'} % feval(theType, theHandles(i)) % otherwise % end % switch theParentType % case 'figure' % set(theParent, 'CurrentObject', theHandles(i)) % otherwise % end % end % end %end fclose(fout); disp(' ## Installing: "busy.m" (text)') fout = fopen('busy.m', 'w'); %function Busy(theFigure) % %% Busy -- Set the watch-cursor. %% Busy(theFigure) sets the watch-cursor in theFigure. %% The companion routine is "Idle". % %% Copyright (C) 1996 Dr. Charles R. Denham, ZYDECO. %% All Rights Reserved. % %if ~any(findobj('Type', 'figure')), return, end % %if nargin < 1 % theFigure = gcf; %end % %set(theFigure, 'Pointer', 'watch'); fclose(fout); disp(' ## Installing: "calls.m" (text)') fout = fopen('calls.m', 'w'); %function [varargout] = calls(theFcn, varargin) % %% calls -- List of function calls. %% calls('demo') demonstrates itself by listing the %% routines that would be called by "bessel(2, 1)". %% [...] = calls('theFcn', ...) executes 'theFcn' with %% the given arguments, then displays the list of M %% and Mex routines that were called, according to the %% Matlab "which" function. The list of full-path names %% is also placed in the caller's "ans". If the list is %% empty, then all the calls were made to "built-in" %% functions. %% %% NOTE: When using this routine to assist a bundling %% procedure, be sure not to include files whose %% respective copyrights would be violated. % %% Copyright (C) 2000 Dr. Charles R. Denham, ZYDECO. %% All Rights Reserved. %% Disclosure without explicit written consent from the %% copyright owner does not constitute publication. % %% Version of 18-Apr-2000 09:11:50. %% Updated 11-Jan-2001 10:17:36. % %if nargout > 0, varargout = cell(1, nargout); end % %if nargin < 1, help(mfilename), theFcn = 'demo'; end % %if isequal(theFcn, 'demo') % calls('bessel', 2, 1) % return %end % %clear functions %clear mex % %if nargout > 0 % if nargin > 1 % [varargout{:}] = feval(theFcn, varargin{:}); % else % [varargout{:}] = feval(theFcn); % end %else % if nargin > 1 % feval(theFcn, varargin{:}); % else % feval(theFcn); % end %end % %[theCalled, theMexCalled] = inmem; %isMex = ones(length(theCalled)+length(theMexCalled), 1); %isMex(1:length(theCalled)) = 0; %theCalled = [theCalled; theMexCalled]; %[theCalled, indices] = sort(theCalled); %isMex = isMex(indices); % %theNames = theCalled; % %for i = 1:length(theCalled) % theCalled{i} = which(theCalled{i}); %end % %w = which(mfilename); %for i = length(theCalled):-1:1 % if isequal(w, theCalled{i}) % theCalled(i) = []; % theNames(i) = []; % break % end %end % %if isempty(theCalled) % theCalled = ' (none)'; %end % %assignin('caller', 'ans', theCalled) % %nmax = 0; %for i = 1:length(theNames) % nmax = max(nmax, length(theNames{i})); %end % %blank = char(zeros(1, nmax) + abs(' ')); %for i = 1:length(theNames) % temp = blank; % if isMex(i) % temp = [temp ' Mex ']; % else % temp = [temp ' M ']; % end % temp(1:length(theNames{i})) = theNames{i}; % theCalled{i} = [temp ' ' theCalled{i}]; %end % %disp(' ') %disp([' ## M-files and Mex-files called by "' theFcn '":']) %disp(' ') %disp(theCalled) % %clear functions fclose(fout); disp(' ## Installing: "crossings.m" (text)') fout = fopen('crossings.m', 'w'); %function theResult = crossings(z1, z2, varargin) % %% crossings -- Index where a polyline crosses a line. %% crossings(N) demonstrates itself with N polyline %% points, where N defaults to 10. %% crossings(z1, z2) returns decimal-indices in polyline %% z1 where line-segment z2 (both complex) crosses it. %% Zero represents segments that do not cross. %% crossings(x1, y1, x2, y2) is an alternative syntax. % %% Copyright (C) 2000 Dr. Charles R. Denham, ZYDECO. %% All Rights Reserved. %% Disclosure without explicit written consent from the %% copyright owner does not constitute publication. % %% Version of 12-Jul-2000 09:05:48. %% Updated 30-Sep-2002 16:00:42. % %if nargin < 1, help(mfilename), z1 = 'demo'; end % %if isequal(z1, 'demo'), z1 = 10; end %if ischar(z1), z1 = eval(z1); end % %if length(z1) == 1 % n = z1; % z1 = sort(rand(1, n)) + sqrt(-1)*rand(1, n); % z2 = rand(1, 2) + sqrt(-1)*rand(1, 2); % hold off % plot(real(z1), imag(z1), 'g', ... % real(z2), imag(z2), 'r') % tic % result = feval(mfilename, z1, z2); % disp([' ## Elapsed time: ' int2str(round(toc)) ' s']) % if any(result) % zi = interp1(1:length(z1), z1, result(result ~= 0)); % hold on % plot(real(zi), imag(zi), 'bo') % end % hold off % title([mfilename ' ' int2str(n)]) % figure(gcf) % try, zoomsafe, catch, end % if nargout > 0 % theResult = result; % else % crossing_indices = result(result ~= 0) % end % return %end % %if nargin > 3 % z1 = z1 + sqrt(-1)*z2; % z2 = varargin{1} + sqrt(-1)*varargin{2}; %end % %if length(z2) > 2 % temp = z1; z1 = z2; z2 = temp; %end % %% *** The following note not yet correct. *** %% NOTE: This routine can be vectorized by using %% "tensor_sol" to compute all the crossings (roots) at %% once. The problem to be solved is A = [x1 1; x2 1] %% and b = [y1; y2], where each of the entries extends %% into the third dimension, one element per line segment. %% Call "tensor_sol(A, b, 2, 1)". % %z1 = z1(:); %z2 = z2(:); % %result = zeros(length(z1)-1, 1); % %for i = 1:length(z1)-1 % z0 = z1(i); % zd = diff(z1(i:i+1)); % z = (z2 - z0) / zd; % if any(imag(z) >= 0) & any(imag(z) <= 0) % p = polyfit(real(z), imag(z), 1); % root = -p(2) / p(1); % if root >= 0 & root <= 1 % result(i) = root + i; % end % end %end % %if nargout > 0 % theResult = result; %else % disp(result) %end fclose(fout); disp(' ## Installing: "dateaxis.m" (text)') fout = fopen('dateaxis.m', 'w'); %function dateaxis(theTickAxis, theDateFormat, theBias) % %% dateaxis -- Resizeable "datetick" function. %% dateaxis('theTickAxis', theDateFormat, theBias) converts %% the labels of 'theTickAxis' {'x' | 'y' | 'z'} to dates %% in theDateFormat (see "help datestr") and makes the %% affected axis resizeable. The Matlab "datenum" or %% "datestr" that corresponds to zero can be entered as %% theBias. More than one axis can be labeled with dates %% by stringing 'theTickAxis' codes together, as in 'xy'. %% The input defaults are 'x', 2, and 0, respectively. %% dateaxis('demo') demonstrates itself. % %% Copyright (C) 1997 Dr. Charles R. Denham, ZYDECO. %% All Rights Reserved. %% Disclosure without explicit written consent from the %% copyright owner does not constitute publication. % %% Version of 26-May-1998 11:03:32. % %if nargin < 1, theTickAxis = 'x'; end % %% Demonstration. % %if isequal(theTickAxis, 'demo') % help(mfilename) % theNow = now; % t = -50:10:50; % theTitle = 'Original'; theXLabel = 'x'; theYLabel = 'y'; % for i = 1:2 % subplot(2, 1, i) % plot([0 -50; 0 0], [-50 0; 0 0], 'r-', t, t, '-o') % axis(55 * [-1 1 -1 1]) % text(+5, 0, 'now') % title(theTitle), xlabel(theXLabel), ylabel(theYLabel) % theTitle = ['dateaxis(''x'', 2, now)']; % theXLabel = 'Date'; theYLabel = 'Day Number'; % end % set(gcf, 'Name', 'DateAxis Demo') % dateaxis('x', 2, theNow) % figure(gcf) % return %end % %% Defaults. % %if nargin < 2, theDateFormat = 2; end %if nargin < 3, theBias = 0; end %if isstr(theBias), theBias = datenum(theBias); end % %% Process each 'tick-axis' code. % %for k = 1:length(theTickAxis) % %% Revert to "auto" tick-labels temporarily. % % switch upper(theTickAxis(k)) % case {'X', 'Y', 'Z'} % set(gca, [theTickAxis(k) 'TickMode'], 'auto') % set(gca, [theTickAxis(k) 'TickLabelMode'], 'auto') % otherwise % help(mfilename) % error([' ## Unknown Tick-Axis Designation: ' theTickAxis(k) '.']); % end % %% Convert ticks to date-strings. % % theTicks = get(gca, [theTickAxis(k) 'Tick']); % theTickLabels = cell(size(theTicks)); % for i = 1:length(theTicks) % theTicklabels{i} = ''; % if rem(i, 2) % if nargin < 2 % theTickLabels{i} = datestr(theTicks(i)+theBias); % else % theTickLabels{i} = datestr(theTicks(i)+theBias, theDateFormat); % end % end % end % set(gca, [theTickAxis(k) 'Tick'], theTicks, ... % [theTickAxis(k) 'TickLabel'], theTickLabels) %end % %% Make resizeable if called directly. % %if isempty(gcbo) % if nargin < 2 % theResizeFcn = ['dateaxis(''' theTickAxis ''');']; % elseif ischar(theDateFormat) % theResizeFcn = ['dateaxis(''' theTickAxis ''', ''' theDateFormat ''', ' num2str(theBias) ');']; % else % theResizeFcn = ['dateaxis(''' theTickAxis ''', ' int2str(theDateFormat) ', ' num2str(theBias) ');']; % end % set(get(gca, 'Parent'), 'ResizeFcn', theResizeFcn) %end fclose(fout); disp(' ## Installing: "datenum2julian.m" (text)') fout = fopen('datenum2julian.m', 'w'); %function theJulian = datenum2julian(theDateNum) % %% datenum2julian -- Convert Julian Day to Matlab datenum. %% datenum2julian(theDateNum) converts theDayNum (Matlab %% datenum) to its equivalent Julian day. The Julian %% day is referenced to midnight, not noon. % %% Copyright (C) 1998 Dr. Charles R. Denham, ZYDECO. %% All Rights Reserved. %% Disclosure without explicit written consent from the %% copyright owner does not constitute publication. % %% Version of 26-Oct-1998 15:49:22. % %if nargin < 1, help(mfilename), return, end % %t0 = datenum(1968, 5, 23) - 2440000; % May 23, 1968. % %result = theDateNum - t0; % %if nargout > 0 % theJulian = result; %else % disp(result) %end fclose(fout); disp(' ## Installing: "deg2dms.m" (text)') fout = fopen('deg2dms.m', 'w'); %function dms=deg2dms(deg) % %%DEG2DMS Converts angles from degrees to deg:min:sec vector format %% %% dms = DEG2DM(deg) converts angles from degrees to deg:min:sec vector %% format. %% %% See also DMS2DEG, DEG2RAD, MAT2DMS, DMS2MAT, ANGLEDIM, ANGL2STR % %% Copyright 1996-2002 Systems Planning and Analysis, Inc. and The MathWorks, Inc. %% Written by: E. Byrns, E. Brown %% $Revision: 1.10 $ $Date: 2002/03/20 21:24:58 $ % % %if nargin==0 % error('Incorrect number of arguments') %elseif ~isreal(deg) % warning('Imaginary parts of complex ANGLE argument ignored') % deg = real(deg); %end % %% Test for empty inputs % %if isempty(deg); dms = []; return; end % %% Construct a sign vector which has +1 when deg >= 0 and -1 when deg < 0. % %signvec = sign(deg); %signvec = signvec + (signvec == 0); % Enforce +1 when deg == 0 % %% Compute the degrees, minutes and seconds % % %deg = abs(deg); % Work in absolute value. Signvec will set sign later %d = fix(deg); % Degrees %ms = 60*(deg - d); % Minutes and seconds %m = fix(ms); % Minutes %s = 60*(ms - m); % Seconds % %% Determine where to store the sign of the angle. It should be %% associated with the largest nonzero component of d:m:s. % %dsign = signvec .* (d~=0); % Associate with degrees %msign = signvec .* (d==0 & m~=0); % Assoicate with minutes (d = 0) %ssign = signvec .* (d==0 & m==0 & s~=0); % Associate with seconds (d = m = 0) % %% In the application of signs below, the comparison with 0 is used so that %% the sign vector contains only +1 and -1. Any zero occurances causes %% data to be lost when the sign has been applied to a higher component %% of d:m:s. % %d = ((dsign==0) + dsign).*d; % Apply signs to the degrees %m = ((msign==0) + msign).*m; % Apply signs to minutes %s = ((ssign==0) + ssign).*s; % Apply signs to seconds % %dms = mat2dms(d,m,s); % Construct the dms vector for output % % fclose(fout); disp(' ## Installing: "demonstrate.m" (text)') fout = fopen('demonstrate.m', 'w'); %function theResult = demonstrate(varargin) % %% demonstrate -- Evaluate and display a command. %% demonstrate ... or demonstrate('...') evaluates %% the concatenated argument(s) as a single command %% and returns or displays a single string showing %% the answer adjacent to the command itself. %% demonstrate (no argument) shows help and %% demonstrates several commands. % %% Copyright (C) 1998 Dr. Charles R. Denham, ZYDECO. %% All Rights Reserved. %% Disclosure without explicit written consent from the %% copyright owner does not constitute publication. % %% Version of 14-Aug-1998 09:12:02. % %if nargin < 1 & nargout < 1 % help(mfilename) % demonstrate datestr(now) % demonstrate sqrt(2) % demonstrate min(2, 3) % demonstrate 2 * 3 % oldWarning = warning; % warning off % demonstrate [-1 0 1] / 0 % warning(oldWarning) % return %end % %theCommand = ''; %for i = 1:length(varargin) % if i > 1, theCommand = [theCommand ' ']; end % theCommand = [theCommand varargin{i}]; %end % %okay = 1; %theAnswer = []; %lasterr('') %theAnswer = evalin('caller', theCommand, '[]'); %if ~isempty(lasterr), theAnswer = ['Error: ' lasterr]; end % %result = [theCommand ' ==> ' mat2str(theAnswer)]; % %if nargout > 0 % theResult = result; %else % disp([' ' result]) %end fclose(fout); disp(' ## Installing: "describe.m" (text)') fout = fopen('describe.m', 'w'); %function status = describe(theItem, howMuch) % %% describe -- Explanation of an item. %% describe('theFunction') shows help for 'theFunction'. %% describe(theObject) describes theObject itself, but not %% its inherited parts. %% describe(theObject, 'full') describes theObject fully. %% describe(theNonObject, ...) describes theNonObject. % %% Copyright (C) 1996 Dr. Charles R. Denham, ZYDECO. %% All Rights Reserved. %% Disclosure without written consent from the %% copyright owner does not constitute publication. % %if nargin < 1, describe('describe'), return, end %if nargin < 2, howMuch = ''; end % %theName = inputname(1); % %if isstr(theItem) % help(theItem) % elseif isobject(theItem) % disp(' ') % if ~isempty(theName) % disp([' ## Name: ' theName]) % end % if isobject(theItem) % disp([' ## Public Class: ' class(theItem)]) % s = super(theItem); % while isobject(s) % disp([' ## Public SuperClass: ' class(s)]) % s = super(s); % end % disp([' ## Protected Methods:']) % theMethods = methods(class(theItem)); % for i = 1:length(theMethods) % if strcmp(class(theItem), theMethods{i}) % disp([' ' class(theItem) '/' theMethods{i} '() // Constructor']) % else % disp([' ' class(theItem) '/' theMethods{i} '()']) % end % end % disp([' ## Private Fields:']), disp(struct(theItem)) % if strcmp(lower(howMuch), 'full') % if isobject(super(theItem)) % disp([' ## Inherited by ' class(theItem) ':']) % describe(super(theItem), 'full') % theItem = super(theItem); % end % end % end % else % disp([' ## Name: ' theName]) % disp([' ## Class: ' class(theItem)]) % disp([' ## Value:']) % disp(theItem) %end fclose(fout); disp(' ## Installing: "dhms.m" (text)') fout = fopen('dhms.m', 'w'); %function theResult = dhms(theArg) % %% dhms -- Convert to/from dhms time-string format. %% dhms('theTimeString') converts 'theTimeString' of %% the form '1d2h3m4s' to decimal days. Multiply %% the result by 86400 to get decimal seconds. %% dhms(theDecimalDays) converts theDecimalDays into a %% time-string of the format '1d2h3m4s', rounded to the %% nearest second. %% dhms (no argument) demonstrates itself. % %% Copyright (C) 1998 Dr. Charles R. Denham, ZYDECO. %% All Rights Reserved. %% Disclosure without explicit written consent from the %% copyright owner does not constitute publication. % %% Version of 16-Oct-1998 18:09:35. % %if nargin < 1, theArg = 'demo'; end % %if isequal(theArg, 'demo') % help(mfilename) % format long % theTimeString = '9d23h59m59s' % theDecimalDays = dhms2d(theTimeString) % theTimeString = d2dhms(theDecimalDays) % format short % return %end % %switch class(theArg) %case 'double' % result = d2dhms(theArg); %case 'char' % result = dhms2d(theArg); %otherwise % help(mfilename) % warning([' ## Invalid argument type: ' class(theArg)]) % result = []; %end % %if nargout > 0 % theResult = result; %else % disp(result) %end % % %function theResult = d2dhms(theDecimalDays) % %% d2dhms -- Convert decimal days to '1d2h3m4s' time-string. %% d2dhms(theDecimalDays) converts theDecimalDays into a %% time-string of the format '1d2h3m4s', rounded to the %% nearest second. %% d2dhms (no argument) demonstrates itself. %% %% Also see: dhms2d. % %% Copyright (C) 1998 Dr. Charles R. Denham, ZYDECO. %% All Rights Reserved. %% Disclosure without explicit written consent from the %% copyright owner does not constitute publication. % %% Version of 07-Oct-1998 08:16:05. % %if nargin < 1 % help(mfilename) % theDecimalDays = 'demo'; %end % %if isequal(theDecimalDays, 'demo') % theDecimalDays = dhms2d('9d23h59m59s') % theTimeString = d2dhms(theDecimalDays) % return %end % %t = theDecimalDays; % %d = fix(t); %t = rem(t, 1) * 24; %h = fix(t); %t = rem(t, 1) * 60; %m = fix(t); %t = rem(t, 1) * 60; %s = round(t); % %result = ''; %if any(d), result = [result int2str(d) 'd']; end %if any(h), result = [result int2str(h) 'h']; end %if any(m), result = [result int2str(m) 'm']; end %if any(s), result = [result int2str(s) 's']; end % %if isempty(result), result = '0s'; end % %if nargout > 0 % theResult = result; %else % disp(result) %end % % %function theResult = dhms2d(theTimeString) % %% dhms2d -- Convert dhms time-string to decimal days. %% dhms('theTimeString') converts 'theTimeString' of %% the form '1d2h3m4s' to decimal days. Multiply %% the result by 86400 to get decimal seconds. %% dhms2d (no argument) demonstrates itself. %% %% Also see: d2dhms. % %% Copyright (C) 1998 Dr. Charles R. Denham, ZYDECO. %% All Rights Reserved. %% Disclosure without explicit written consent from the %% copyright owner does not constitute publication. % %% Version of 06-Oct-1998 21:19:25. % %if nargin < 1 % help(mfilename) % theTimeString = 'demo'; %end % %if isequal(theTimeString, 'demo') % theTimeString = '9d23h59m60s' % theDecimalDays = dhms2d(theTimeString) % return %end % %t = lower(theTimeString); % %flag = 0; % %if any(t == 's') % t = strrep(t, 's', '*1'); % flag = 1; %end % %if any(t == 'm') % if flag % t = strrep(t, 'm', '*60+'); % else % t = strrep(t, 'm', '*60'); % end % flag = 1; %end % %if any(t == 'h') % if flag % t = strrep(t, 'h', '*3600+'); % else % t = strrep(t, 'h', '*3600'); % end % flag = 1; %end % %if any(t == 'd') % if flag % t = strrep(t, 'd', '*86400+'); % else % t = strrep(t, 'd', '*86400'); % end %end % %result = eval(t) / 86400; % %if nargout > 0 % theResult = result; %else % disp(result) %end % fclose(fout); disp(' ## Installing: "dirinfo.m" (text)') fout = fopen('dirinfo.m', 'w'); %function result = dirinfo % %% dirinfo -- Information about current-directory. %% dirinfo (no argument) returns information about %% the current-directory: number of files, directories, %% and bytes. The tally works recursively through all %% the embedded directories. % %% Copyright (C) 2001 Dr. Charles R. Denham, ZYDECO. %% All Rights Reserved. %% Disclosure without explicit written consent from the %% copyright owner does not constitute publication. % %% Version of 25-Sep-2001 15:15:24. %% Updated 25-Sep-2001 15:20:54. % %files = 0; %dirs = 0; %bytes = 0; % %d = dir; % %for i = 1:length(d) % if d(i).isdir % cd(d(i).name) % y = feval(mfilename); % files = files + y.files; % dirs = dirs + 1; % bytes = bytes + y.bytes; % cd .. % else % files = files + 1; % bytes = bytes + d(i).bytes; % end %end % %x.files = files; %x.dirs = dirs; %x.bytes = bytes; % %if nargout > 0 % result = x; %else % disp(x) %end fclose(fout); disp(' ## Installing: "doubleclick.m" (text)') fout = fopen('doubleclick.m', 'w'); %function theResult = doubleclick(double_click_time) % %% doubleclick -- Trap for double-clicks. %% doubleclick(double_click_time) returns TRUE if a click %% is detected while "doubleclick" itself is executing; %% otherwise, FALSE. Call "doubleclick" at the top %% of a "WindowButtonDown" or "ButtonDown" callback. %% The 'Interruptible' property of the callback-object %% must be 'on'. Default double_click_time is 0.5 sec. %% A valid double-click causes two values to be returned %% in succession: first, a logical(1), then []. The %% latter can be ignored; it represents the first click %% that initiated the process. For a valid single-click, %% only logical(0) is returned. % %% Copyright (C) 1997 Dr. Charles R. Denham, ZYDECO. %% All Rights Reserved. %% Disclosure without explicit written consent from the %% copyright owner does not constitute publication. % %% Version of 25-Jul-1998 09:47:16. %% Updated 04-Sep-2001 02:42:01. % %persistent CLICK_COUNT % Use "persistent in Matlab 5.2+. % %% Increase the following if the %% double-click-time seems too short. % %if nargin < 1, double_click_time = 1/2; end % %DOUBLE_CLICK_TIME = double_click_time; % Seconds. % %if isempty(CLICK_COUNT), CLICK_COUNT = 0; end % %CLICK_COUNT = CLICK_COUNT + 1; % %if CLICK_COUNT == 1 % tic % while isequal(CLICK_COUNT, 1) & toc < DOUBLE_CLICK_TIME, end %end % %drawnow % Process the event-cue. % %% Note: %% Despite the "drawnow" seen above, Matlab does not %% update the "SelectionType" in timely fashion, so %% it cannot be used to trap a double-click properly. % %result = (CLICK_COUNT > 1); % %CLICK_COUNT = []; % %if nargout > 0 % theResult = result; %else % disp(result) %end fclose(fout); disp(' ## Installing: "ezgrid.m" (text)') fout = fopen('ezgrid.m', 'w'); %function [xi, yi, zi] = ezgrid(x, y, z, nx, ny, doPlot) % %% ezgrid -- Easy GRIDDATA scheme. %% ezgrid('demo') calls "ezgrid(200)". %% ezgrid(N) demonstrates itself with N points (default = 200). %% [xi, yi, zi] = ezgrid(x, y, z, nx, ny, doPlot) grids the z(x, y) %% data, returning ny-by-nx arrays zi(xi, yi). A contour plot %% is shown if "doPlot" evaluates to TRUE. % %% Copyright (C) 2002 Dr. Charles R. Denham, ZYDECO. %% All Rights Reserved. %% Disclosure without explicit written consent from the %% copyright owner does not constitute publication. % %% Version of 02-Apr-2002 11:54:05. %% Updated 02-Apr-2002 12:08:33. % %if nargin < 1, help(mfilename), x = 'demo'; end %if isequal(x, 'demo'), x = 200; end %if ischar(x), x = eval(x); end % %% Demonstration. % %if length(x) == 1 % n = ceil(x); % m = ceil(sqrt(x)); % x = rand(n, 1); % y = rand(n, 1); % z = rand(n, 1); % feval(mfilename, x, y, z, m, m, 1) % return %end % %if nargin < 3, nx = 21; end %if nargin < 4, ny = nx; end %if nargin < 5, doPlot = ~~0; end % %x = x(:); %y = y(:); %z = z(:); % %% Remove (x, y) minima to assist GRIDDATA/QHULL. % %xmin = min(x); %ymin = min(y); % %x = x - xmin; %y = y - ymin; % %% Margin for the grid. % %dx = max(x)/(nx-1); %dy = max(y)/(ny-1); % %% Generate the MESHGRID. % %xlin = linspace(min(x)-dx/2, max(x)+dx/2, nx); %ylin = linspace(min(y)-dy/2, max(y)+dy/2, ny); % %[xxi, yyi] = meshgrid(xlin, ylin); % %% Call GRIDDATA. % %zzi = griddata(x, y, z, xxi, yyi); % %% Restore the minima. % %xxi = xxi + xmin; %yyi = yyi + ymin; % %% Automatic plot. % %if ~~doPlot(:) % figure(gcf) % hold off % contour(xxi, yyi, zzi) % hold on % x = x + xmin; % y = y + ymin; % marker = 'ro'; % if length(x) > 200, marker = 'r+'; end % if length(x) > 1000, marker = 'r.'; end % plot(x, y, marker) % hold off % title([mfilename '(' int2str(length(x)) ')']) % xlabel x % ylabel y % try % zoomsafe on % catch % disp([' ## ZOOMSAFE not available.']) % end %end % %% Output. % %if nargout > 0 % xi = xxi; yi = yyi; zi = zzi; %end fclose(fout); disp(' ## Installing: "fcat.m" (text)') fout = fopen('fcat.m', 'w'); %function theBytesOut = fcat(theInput, theOutput) % %% fcat -- Concatenate files. %% fcat('theInput', 'theOutput') concatenates all files %% encompassed by "dir('theInput')" to 'theOutput' file. %% The output file is created if it does not already %% exist. The number of bytes output is returned. % %% Copyright (C) 2000 Dr. Charles R. Denham, ZYDECO. %% All Rights Reserved. %% Disclosure without explicit written consent from the %% copyright owner does not constitute publication. % %% Version of 19-Jul-2000 15:09:05. %% Updated 19-Jul-2000 15:29:15. % %if nargout > 0, theBytesOut = 0; end % %if nargin < 2, help(mfilename), return, end % %if ischar(theInput) % theInput = dir(theInput); %end % %if isempty(theInput) % disp([' ## ' mfilename ' -- No inputs exist.']) % return %end % %fout = fopen(theOutput, 'a'); % %if fout < 0 % disp([' ## ' mfilename ' -- No such output file: ' theOutput]) % return %end % %bytes_out = 0; % %for i = 1:length(theInput) % w = which(theInput(i).name); % fin = fopen(w, 'r'); % if fin >= 0 % theBytes = fread(fin); % fclose(fin); % if ~isempty(theBytes) % c = fwrite(fout, theBytes); % bytes_out = bytes_out + c; % end % end %end % %fclose(fout); % %if nargout > 0, theBytesOut = bytes_out; end fclose(fout); disp(' ## Installing: "fcomment.m" (text)') fout = fopen('fcomment.m', 'w'); %function status = fcomment(infile, outfile) % %% fcomment -- Convert text file for "load" compatibility. %% fcomment('infile', 'outfile') converts the "infile" to the %% "outfile" by prepending each comment-line with '%' and %% passing all other lines intact. The "uigetfile" and %% "uiputfile" dialogs are invoked if areguments are not %% provided. % %% Copyright (C) 1998 Dr. Charles R. Denham, ZYDECO. %% All Rights Reserved. %% Disclosure without explicit written consent from the %% copyright owner does not constitute publication. % %% Version of 09-Nov-1998 05:37:45. %% Updated 04-Aug-1999 11:16:48. % %if nargin < 1 % help(mfilename) % [theFile, thePath] = uigetfile('*.*', 'Select A File:'); % if ~any(theFile), return, end % infile = [thePath theFile]; %end % %theSuggested = infile; %i = find(theSuggested == filesep); %if any(i), theSuggested(1:i(length(i))) = []; end %i = find(theSuggested == '.'); %if any(i), theSuggested(i(length(i)):length(theSuggested)) = []; end %theSuggested = [theSuggested '.out']; % %if nargin < 2 % [theFile, thePath] = uiputfile(theSuggested, 'Save File As:'); % if ~any(theFile), return, end % outfile = [thePath theFile]; %end % %f = fopen(infile, 'r'); %if f < 0, return; end %g = fopen(outfile, 'w'); %if g < 0, fclose(f); return, end % %while (1) % s = fgets(f); %disp(s) % if isequal(s, -1), break; end % t = upper(s); % if any(t) & any(t >= 'A' & t ~= 'E' & t <= 'Z') % s = ['% ' s]; % end % fwrite(g, s); %end % %fclose(f); %fclose(g); fclose(fout); disp(' ## Installing: "fig2jpeg.m" (text)') fout = fopen('fig2jpeg.m', 'w'); %function theOutputInfo = fig2jpeg(theFilename, theFigure, theQuality) % %% fig2jpeg -- Save a visible figure in JPEG format. %% fig2jpeg('theFilename', theFigure, theQuality) saves theFigure %% (must exist and be visible; default = gcf) to 'theFilename' %% (default = 'unnamed.jpg'), with theQuality (default = 100). %% If no filename is given, the Matlab "uiputfile" dialog is %% invoked. If an output argument is provided, the "imfinfo" %% string is returned. % %% Copyright (C) 2000 Dr. Charles R. Denham, ZYDECO. %% All Rights Reserved. %% Disclosure without explicit written consent from the %% copyright owner does not constitute publication. % %% Version of 03-Jan-2000 17:35:28. %% Updated 04-Jan-2000 14:03:25. % %if nargout > 0, theOutputInfo = []; end % %if ~any(findobj('Type', 'figure', 'Visible', 'on')) % disp(' ## No visible figures.') % return %end % %if nargin < 1 % [f, p] = uiputfile('unnamed.jpg', 'Save Figure As JPEG:'); % if ~any(f) % help(mfilename) % return % end % if p(end) ~= filesep, p(end+1) = filesep; end % theFilename = [p f]; %end %if nargin < 2, theFigure = gcf; end %if nargin < 3, theQuality = 100; end % %theOldFigure = gcf; % %figure(theFigure) %[x, map] = getframe(theFigure); %imwrite(x, map, theFilename, 'jpg', 'Quality', theQuality) % %figure(theOldFigure) % %if nargout > 0 % theOutputInfo = imfinfo(theFilename); %end fclose(fout); disp(' ## Installing: "filepick_install.m" (text)') fout = fopen('filepick_install.m', 'w'); %% Installer: "filepick_install.m" %% Created: 15-Aug-2001 11:19:32. % %function bund_driver % %% bund_driver -- Driver for "bund" bundles. %% bund_driver (no arguments) contains Matlab commands %% to inflate the instructions and files that are %% encoded into the "bund_data" function of this package. % %% Copyright (C) 2001 Dr. Charles R. Denham, ZYDECO. %% All Rights Reserved. %% Disclosure without explicit written consent from the %% copyright owner does not constitute publication. % %% Version of 14-Jun-2001 10:54:16. %% Updated 03-Aug-2001 13:43:17. % %help(mfilename) % %BINARY_TAG = '?'; % %CR = char(13); %LF = char(10); % %comp = upper(computer); %if any(findstr(comp, 'PCWIN')) % Windows. % NL = [CR LF]; %elseif any(findstr(comp, 'MAC2')) % Macintosh. % NL = CR; %else % Unix. % NL = LF; %end % %c = zeros(1, 256); %c(abs('0'):abs('9')) = 0:9; %c(abs('a'):abs('f')) = 10:15; % %disp([' ']) %disp([' ## This installer is ready to expand its contents,']) %disp([' ## starting in the present directory: "' pwd '"']) %disp([' ## To abort, execute an interruption now.']) %disp([' ## Otherwise, to continue, press any key.']) %disp([' ']) % %try % pause %catch % disp([' ## Installation interrupted.']) % disp([' ']) % return %end % %tic % %w = which(mfilename); % %fin = fopen(w, 'r'); %if fin < 0, return, end % %found = ~~0; %while ~found % s = fgetl(fin); % if isequal(s, -1) % fclose(fin); % return % end % s = strrep(s, LF, ''); % Not necessary? % s = strrep(s, CR, ''); % Not necessary? % if isequal(s, 'function bund_data') % found = ~~1; % end %end % %fout = -1; % %done = ~~0; %while ~done % s = fgetl(fin); % if isequal(s, -1) % fclose(fin); % return % end % if length(s) > 0 % if s(1) ~= '%' % f = findstr(s, 'bund_setdir'); % if any(f) % theDir = eval(strrep(s, 'bund_setdir', '')); % status = mkdir(theDir); % switch status % case 1 % disp([' ## Directory created: "' theDir '"']) % case 2 % disp([' ## Directory exists: "' theDir '"']) % otherwise % error([' ## Error while making new directory.']) % end % % try % cd(theDir) % catch % error([' ## Unable to go to directory: "' theDir '"']) % end % else % try % eval(s); % catch % error([' ## Unable to evaluate: "' s '"']) % end % end % elseif length(s) > 1 & s(2) == BINARY_TAG % hx = double(s(3:end)); % Assume hex data. % bin = 16*c(hx(1:2:end)) + c(hx(2:2:end)); % fwrite(fout, bin, 'uchar'); % else % fprintf(fout, '%s', s(2:end)); % fprintf(fout, NL); % end % end %end % %fclose(fin); % %disp([' ## Elapsed time: ' num2str(fix(10*toc)/10) ' s.']) % %function bund_data %bund_setdir('filepick') %bund_setdir('@filepick') % %disp(' ## Installing: "event.m" (text)') %fout = fopen('event.m', 'w'); %%function theResult = Event(self, theMode) %% %%% filepick/event -- Event handler. %%% Event(self) handles mouse events associated %%% with self, a "filepick" object. %% %%% Copyright (C) 2001 Dr. Charles R. Denham, ZYDECO. %%% All Rights Reserved. %%% Disclosure without explicit written consent from the %%% copyright owner does not constitute publication. %% %%% Version of 13-Jun-2001 15:21:01. %%% Updated 14-Jun-2001 15:49:21. %% %%if nargin < 1, help(mfilename), return, end %%if nargin < 2, theMode = 'normal'; end %% %%theFigure = self.itSelf; %% %%theDirectory = findobj(theFigure, 'Tag', 'Directory'); %%theSource = findobj(theFigure, 'Tag', 'Source'); %%theDestination = findobj(theFigure, 'Tag', 'Destination'); %%theOkay = findobj(theFigure, 'Tag', 'Okay'); %% %%theSourceString = get(theSource, 'String'); %%theDestinationString = get(theDestination, 'String'); %% %%theDirectoryString = get(theDirectory, 'String'); %%theDirectoryValue = get(theDirectory, 'Value'); %% %%theTag = get(gcbo, 'Tag'); %%theValue = get(gcbo, 'Value'); %%theOldValue = get(gcbo, 'UserData'); %% %%% Update the GUI. %% %%switch theMode %%case 'update' %% filterspec = self.itsFilterSpec; %% p = pwd; %% if p(end) ~= filesep, p(end+1) = filesep; end %% f = find(p == filesep); %% theDirectoryString = cell(length(f), 1); %% k = 0; %% for i = 1:length(f) %% theDirectoryString{i} = p(k+1:f(i)-1); %% k = f(i); %% end %% set(theDirectory, 'String', theDirectoryString, ... %% 'Value', length(theDirectoryString)) %% theTag = ''; %% files = dir; %% theSourceString = cell(length(files), 1); %% for i = length(files):-1:1 %% name = files(i).name; %% theSourceString{i} = name; %% if files(i).isdir %% name = ['<' name '>']; %% theSourceString{i} = name; %% elseif ~isempty(filterspec) %% okay = ~~0; %% for j = 1:length(filterspec) %% f = findstr1(name, filterspec{j}); %% if any(f), okay = ~~1; break, end %% end %% if ~okay, theSourceString(i) = []; end %% end %% end %% if isempty(theSourceString) %% theSourceString = {'(no files)'}; %% end %% set(theSource, 'String', theSourceString, 'Value', 1, 'UserData', files) %% return %%otherwise %%end %% %%% Process mouse action. %% %%switch lower(theTag) %%case 'directory' %% k = length(theDirectoryString) - theDirectoryValue; %% for i = 1:k, cd .., end %% event(self, 'update') %% return %%case 'source' % Not correct. %% name = theSourceString{theValue}; %% if name(1) == '<' & name(end) == '>' % Directory. %% name = name(2:end-1); %% cd(name) %% event(self, 'update') %% return %% elseif ~isequal(name, '(no files)') %% theSrc = theSource; %% theDst = theDestination; %% theTag = 'Move'; %% end %%case 'destination' %% theSrc = theDestination; %% theDst = theSource; %% theTag = 'Move'; %%otherwise %%end %% %%% Transfer a string. %% %%switch lower(theTag) %%case 'move' %% theSrcList = get(theSrc, 'String'); %% theDstList = get(theDst, 'String'); %% theSrcValue = get(theSrc, 'Value'); %% theDstValue = get(theDst, 'Value'); %% s = theSrcList{theSrcValue}; %% d = theDirectoryString; %% p = ''; %% for i = 1:length(d) %% p = [p d{i} filesep]; %% end %% s = [p s]; %% switch lower(theMode) %% case 'unique' %% theDstList = [theDstList; {s}]; %% theSrcList(theSrcValue) = []; %% theSrcValue = min(theSrcValue, length(theSrcList)); %% theDstValue = length(theDstList); %% case 'multiple' %% if theDst == theDestination %% theDstList = [theDstList; {s}]; %% theDstValue = length(theDstList); %% elseif theDst == theSource %% theSrcList(theSrcValue) = []; %% theSrcValue = min(theSrcValue, length(theSrcList)); %% end %% otherwise %% end %% set(theSrc, 'String', theSrcList, 'UserData', theSrcValue) %% set(theDst, 'String', theDstList, 'UserData', theDstValue) %% if length(theSrcList) > 0, set(theSrc, 'Value', theSrcValue), end %% if length(theDstList) > 0, set(theDst, 'Value', theDstValue), end %% set(theOkay, 'UserData', get(theDestination, 'String')) %%case {'cancel', 'okay'} %% set(theFigure, 'UserData', []) %%otherwise %%end %fclose(fout); % %disp(' ## Installing: "filepick.m" (text)') %fout = fopen('filepick.m', 'w'); %%function [p, f] = filepick(theFilterSpec, theDialogTitle, x, y, varargin) %% %%% filepick/filepick -- Pick one or more files. %%% filepick(filterSpec, dialogTitle, x, y) presents a dialog for %%% selecting one or more files, the full-path names of which are %%% returned in a cell-array. To remove an unwanted selection, %%% click on it. In the directories are marked by <...> triangular %%% brackets. If "Cancel" is chosen, the result will be empty. %%% Several file-filters can be specified as a compact comma-separated %%% list, or as a cell-array of the individual filters, as in: %%% '*.dat,*.nc', or {'*.dat, '*.nc'}. %%% [p, f] = filepick(...) returns the paths and filenames in separate %%% cell-arrays. %% %%% Copyright (C) 2001 Dr. Charles R. Denham, ZYDECO. %%% All Rights Reserved. %%% Disclosure without explicit written consent from the %%% copyright owner does not constitute publication. %% %%% Version of 13-Jun-2001 15:21:01. %%% Updated 14-Jun-2001 15:56:23. %% %%if nargin < 1, theFilterSpec = ''; end %%if nargin < 2, theDialogTitle = 'File Picker'; end %% %%theName = theDialogTitle; %%theMode = 'multiple'; %% %%thePrompt{1} = {'<== Select Files By Single Click ==>'}; %%thePrompt{2} = 'Directory'; %%thePrompt{3} = 'Selected'; %% %%theDirectory = pwd; %%cd(theDirectory) %% %%oldPWD = pwd; %% %%files = dir; %%theSourceList = cell(length(files), 1); %%for i = 1:length(files) %% theSourceList{i} = files(i).name; %%end %% %%theSourceList = [theSourceList(:)]; %%theDestinationList = cell(0, 1); %% %%if nargout > 1, theResult = cell(0, 1); end %% %%theFigure = figure('Name', theName, 'NumberTitle', 'off', ... %% 'WindowStyle', 'modal', 'Visible', 'off', 'Resize', 'off'); %%thePosition = get(theFigure, 'Position'); %%thePosition(2) = thePosition(2) + 0.10 .* thePosition(4); %%thePosition(3) = 0.5 .* thePosition(3); %%thePosition(4) = 0.80 .* thePosition(4); %% %%thePosition(3) = thePosition(3) * 2; %% %%if nargin > 2, thePosition(1) = x; end %%if nargin > 3, thePosition(2) = y; end %% %%set(theFigure, 'Position', thePosition) %% %%fs = theFilterSpec; %%if ~iscell(fs) %% if any(fs) %% if fs(end) ~= ',', fs(end+1) = ','; end %% f = find(fs == ','); %% theFilterSpec = cell(1, length(f)); %% k = 0; %% for i = 1:length(f) %% theFilterSpec{i} = fs(k+1:f(i)-1); %% k = f(i); %% end %% else %% theFilterSpec = []; %% end %%end %% %%theStruct.itSelf = theFigure; %%theStruct.itsFilterSpec = theFilterSpec; %%self = class(theStruct, 'filepick'); %%set(theFigure, 'UserData', self) %% %%if isempty(self), return, end %% %%theFrame = uicontrol('Style', 'frame', 'Visible', 'on', ... %% 'Units', 'normalized', 'Position', [0 0 1 1], ... %% 'BackgroundColor', [0.5 1 1]); %% %%theControls = zeros(7, 1); %%theControls(1) = uicontrol('Style', 'text', 'Tag', 'Label', ... %% 'String', thePrompt{1}, 'HorizontalAlignment', 'center'); %%theControls(2) = uicontrol('Style', 'text', 'Tag', 'Label', ... %% 'String', thePrompt{2}, 'HorizontalAlignment', 'center'); %%theControls(3) = uicontrol('Style', 'text', 'Tag', 'Label', ... %% 'String', thePrompt{3}, 'HorizontalAlignment', 'center'); %%theControls(4) = uicontrol('Style', 'listbox', 'Tag', 'Source', ... %% 'String', theSourceList); %%theControls(5) = uicontrol('Style', 'listbox', 'Tag', 'Destination', ... %% 'String', theDestinationList); %%theControls(6) = uicontrol('Style', 'pushbutton', 'Tag', 'Cancel', ... %% 'String', 'Cancel', 'UserData', []); %%theControls(7) = uicontrol('Style', 'pushbutton', 'Tag', 'Okay', ... %% 'String', 'Okay', 'UserData', theDestinationList); %% %%p = pwd; %%if(p(end) ~= filesep), p(end+1) = filesep; end %%f = find(p == filesep); %%d = cell(length(f), 1); %%k = 0; %%for i = 1:length(d) %% d{i} = p(k+1:f(i)-1); %% k = f(i); %%end %% %%theControls(8) = uicontrol('Style', 'popupmenu', 'Tag', 'Directory', ... %% 'String', d, 'Value', length(d), 'UserData', []); %% %%xx = Inf; %% %%theLayout = [ ... %% 10 10 10 10 10 10 10 10 10 %% 20 20 20 30 30 30 30 30 30 %% 80 80 80 xx xx xx xx xx xx %% 40 40 40 50 50 50 50 50 50 %% 40 40 40 50 50 50 50 50 50 %% 40 40 40 50 50 50 50 50 50 %% 40 40 40 50 50 50 50 50 50 %% 40 40 40 50 50 50 50 50 50 %% 40 40 40 50 50 50 50 50 50 %% 40 40 40 50 50 50 50 50 50 %% xx 60 60 xx xx xx 70 70 xx]; %% %%uilayout(theControls, theLayout, [2 2 96 92]./100) %%set(theFrame, 'UserData', theControls) %% %%theCallback = ['event(get(gcf, ''UserData''), ''' theMode ''')']; %%set(theControls(4:8), 'Callback', theCallback) %%set(theControls(1:3), 'BackgroundColor', [0.5 1 1]); %% %%if any(findstr(computer, 'MAC')) %% set(theControls(4:5), 'FontName', 'Monaco', ... %% 'FontSize', 12, ... %% 'FontAngle', 'normal', ... %% 'FontWeight', 'normal') %%end %% %%if length(varargin) > 0 %% set(theControls(4:5), varargin{:}) %%end %% %%event(self, 'update') %% %%set(theFigure, 'Visible', 'on') %%waitfor(theFigure, 'UserData', []) %% %%result = get(gco, 'UserData'); %% %%cd(oldPWD) %% %%delete(theFigure) %% %%if nargout < 2 %% p = result; %%else %% p = cell(size(result)); %% f = cell(size(result)); %% for i = 1:length(result) %% [p{i}, f{i}] = fileparts(result{i}); %% end %%end %fclose(fout); % %disp(' ## Installing: "version.m" (text)') %fout = fopen('version.m', 'w'); %%function version(self) %% %%% Version of 31-May-2001 15:27:27. %% %%helpdlg(help(mfilename), 'listpick') %fclose(fout); %cd ('..') % %disp(' ## Installing: "uilayout.m" (text)') %fout = fopen('uilayout.m', 'w'); %%function theResult = uilayout(theControls, theLayout, ... %% thePosition, theMargin) %% %%% uilayout -- Layout for ui controls. %%% uilayout(theControls, theLayout) positions theControls %%% according to theLayout, an array whose entries, taken %%% in sorted order, define the rectangular extents occupied %%% by each control. TheLayout defaults to the shape of %%% theControls array. A one-percent margin is %%% imposed between controls. To define a layout region %%% containing no control, use Inf. %%% uilayout(..., thePosition) confines the controls to the %%% given normalized position of the figure. This syntax %%% is useful for embedding controls within a frame. %%% uilayout(....., theMargin) allows the default margin %%% of 0.01 (normalized units) between controls to be %%% set to another value. %%% uilayout (no argument) demonstrates itself. %% %%% Copyright (C) 1997 Dr. Charles R. Denham, ZYDECO. %%% All Rights Reserved. %%% Disclosure without explicit written consent from the %%% copyright owner does not constitute publication. %% %%% Version of 18-Apr-1997 08:07:54. %%% Updated 27-Jan-2000 23:05:13. %% %%if nargin < 1, theControls = 'demo'; help(mfilename), end %% %%if strcmp(theControls, 'demo') %% theLayout = [1 2; %% 3 4; %% 5 Inf; %% 5 6; %% 5 Inf; %% 7 8; %% 9 10; %% 11 12; %% 13 14]; %% [m, n] = size(theLayout); %% thePos = get(0, 'DefaultUIControlPosition'); %% theSize = [n+2 m+2] .* thePos(3:4); %% theFigure = figure('Name', 'UILayout', ... %% 'NumberTitle', 'off', ... %% 'Resize', 'off', ... %% 'Units', 'pixels'); %% thePos = get(theFigure, 'Position'); %% theTop = thePos(2) + thePos(4); %% thePos = thePos .* [1 1 0 0] + [0 0 theSize]; %% thePos(2) = theTop - (thePos(2) + thePos(4)); %% set(theFigure, 'Position', thePos); %% theFrame = uicontrol('Style', 'frame', ... %% 'Units', 'normalized', ... %% 'Position', [0 0 1 1], ... %% 'BackgroundColor', [0.5 1 1]); %% theStyles = {'checkbox'; 'text'; ... %% 'edit'; 'text'; ... %% 'listbox'; 'text'; ... %% 'popupmenu'; 'text'; ... %% 'pushbutton'; 'text'; ... %% 'radiobutton'; 'text'; ... %% 'text'; 'text'}; %% theStrings = {'Anchovies?', '<-- CheckBox --', ... %% 'Hello World!', '<-- Edit --', ... %% {'Now', 'Is', 'The' 'Time' 'For' 'All' 'Good', ... %% 'Men', 'To', 'Come' 'To' 'The' 'Aid' 'Of', ... %% 'Their' 'Country'}, ... %% '<-- ListBox --', ... %% {'Cheetah', 'Leopard', 'Lion', 'Tiger', 'Wildcat'}, ... %% '<-- PopupMenu --', ... %% 'Okay', '<-- PushButton --', ... %% 'Cream?', '<-- RadioButton --', ... %% 'UILayout', '<-- Text --'}; %% theControls = zeros(size(theStyles)); %% for i = 1:length(theStyles) %% theControls(i) = uicontrol('Style', theStyles{i}, ... %% 'String', theStrings{i}, ... %% 'Callback', ... %% 'disp(int2str(get(gcbo, ''Value'')))'); %% end %% set(theControls(1:2:length(theControls)), 'BackGroundColor', [1 1 0.5]) %% set(theControls(2:2:length(theControls)), 'BackGroundColor', [0.5 1 1]) %% thePosition = [1 1 98 98] ./ 100; %% feval(mfilename, theControls, theLayout, thePosition) %% set(theFrame, 'UserData', theControls) %% theStyles, theLayout, thePosition %% if nargout > 0, theResult = theFrame; end %% return %%end %% %%if nargin < 2 %% theLayout = zeros(size(theControls)); %% theLayout(:) = 1:prod(size(theControls)); %%end %%if nargin < 3, thePosition = [0 0 1 1]; end %%if nargin < 4, theMargin = 1/100; end %% %%a = theLayout(:); %%a = a(finite(a)); %%a = sort(a); %%a(diff(a) == 0) = []; %% %%b = zeros(size(theLayout)); %% %%for k = 1:length(a) %% b(theLayout == a(k)) = k; %%end %% %%[m, n] = size(theLayout); %% %%set(theControls, 'Units', 'Normalized') %%theMargin = [1 1 -2 -2] * theMargin; %%for k = 1:min(length(theControls), length(a)) %% [i, j] = find(b == k); %% xmin = (min(j) - 1) ./ n; %% xmax = max(j) ./ n; %% ymin = 1 - max(i) ./ m; %% ymax = 1 - (min(i) - 1) ./ m; %% thePos = [xmin ymin (xmax-xmin) (ymax-ymin)] + theMargin; %%if (1) %% thePos = thePos .* thePosition([3 4 3 4]); %% thePos(1:2) = thePos(1:2) + thePosition(1:2); %%end %% set(theControls(k), 'Position', thePos); %%end %% %%if nargout > 0, theResult = theControls; end %fclose(fout); %cd ('..') fclose(fout); disp(' ## Installing: "findobjs.m" (text)') fout = fopen('findobjs.m', 'w'); %function theResult = findobjs(varargin) % %% findobjs -- Smart "findobj" with relational operators. %% findobjs(...) returns handles in the same fashion %% as "findobj", with the added feature of allowing %% a relational-operator to be appended to each %% property-name, as in "findobjs('Type~=', 'line')". %% The "~=" relationship is processed with the %% Matlab "isequal" function; all others rely on %% "feval('operator', ...)". Handles that do not %% possess the given property-names are ignored, %% as are illegal operators. %% findobj('demo') demonstrates itself. %% %% Also see: "help findobj". % %% Copyright (C) 1999 Dr. Charles R. Denham, ZYDECO. %% All Rights Reserved. %% Disclosure without explicit written consent from the %% copyright owner does not constitute publication. % %% Version of 10-Dec-1999 11:26:09. %% Updated 10-Dec-1999 14:42:23. % %if nargout > 0, theResult = []; end % %if nargin < 1, varargin = {}; end %if isempty(varargin), varargin = {'demo'}; end % %% Demonstration. % %if isequal(varargin{1}, 'demo') % disp(' ') % disp(' ## findobjs demo') % delete(get(gcf, 'Children')) % set(gcf, 'Name', 'findobjs demo') % disp(' ') % s = 'plot(0:10, rand(1, 11), ''o-'')'; % disp([' ## ' s]) % eval(s) % disp(' ') % figure(gcf) % s = 'findobjs(0)'; % disp([' ## ' s]) % eval(s) % disp(' ') % s = 'findobjs(0, ''Type~='', ''axes'', ''Type~='', ''line'')'; % disp([' ## ' s]) % eval(s) % disp(' ') % return %end % %% Get the starting handle. % %theHandle = 0; %if ~ischar(varargin{1}) & ishandle(varargin{1}) % theHandle = varargin{1}; % varargin(1) = []; %end % %% Parse the relational operators, setting %% "==" to the empty-string ''. % %s = []; %for i = 2:2:length(varargin) % k = i/2; % name = lower(varargin{i-1}); % relop = name(name < 'a' | name > 'z'); % if isequal(relop, '=='), relop = ''; end % name = name(name >= 'a' & name <= 'z'); % value = varargin{i}; % s(k).name = name; % s(k).value = value; % s(k).relop = relop; %end % %% Separate the equalities from the others. % %t = s; %for i = length(s):-1:1 % if isempty(s(i).relop) % s(i) = []; % Equality. % else % t(i) = []; % Other. % end %end % %% Get the handles for the equalities, or %% everything if no equalities are given. % %u = []; %for i = 1:length(t) % u{end+1} = t(i).name; % u{end+1} = t(i).value; %end %if isempty(u) % result = findobj(theHandle); %else % result = findobj(theHandle, u{:}); %end % %% Isolate the relational subset, if any. % %if length(s) > 0 % for k = length(result):-1:1 % okay = 0; % try % for i = 1:length(s) % try % val = get(result(k), s(i).name); % catch % break % end % value = s(i).value; % relop = s(i).relop; % % switch relop % case '~=' % okay = ~isequal(val, value); % otherwise % try % okay = feval(relop, val, value); % catch % end % end % % if ~okay, break, end % end % catch % end % if ~all(okay(:)) % result(k) = []; % end % end %end % %% Done. % %if nargout > 0 % theResult = result; %else % assignin('caller', 'ans', result) % if isempty(result) % disp(' Empty matrix: 0-by-1') % else % for i = 1:length(result) % disp([' ## ' num2str(result(i), 16) ': ' get(result(i), 'Type')]) % end % end %end fclose(fout); disp(' ## Installing: "findpt.m" (text)') fout = fopen('findpt.m', 'w'); %function [theResult, theIndex, x, y, z] = findpt(theLine, x, y, z) % %% findpt -- Find the current point. %% findpt(theLine) installs "findpt" in theLine (a handle) if called %% directly, rather than as the result of a callback. In this case, %% theLine defaults to all the lines in the current figure. During %% mouse-down and mouse-move, the (x, y, z) location of the nearest %% actual point on the original mouse-down line is displayed near %% the mouse, in the figure-name, and in the Matlab command window. %% Note: A simple down/up mouse-click (no dragging) causes the tag %% to remain on the plot. It can be erased by clicking on it. %% [theLine, theIndex, x, y, z] = findpt(theLine, x, y, z) returns the %% actual point on theLine [default = gcbo], that is nearest (x, y, z) %% [default = present mouse position]. The returned values are packed %% into a single vector if only one output argument is provided. The %% output (x, y, z) are the actual coordinates of the point. If no %% output arguments are given, the (x, y) result is displayed on the %% plot and in the figure-name while the mouse is down. % %% Copyright (C) 1997 Dr. Charles R. Denham, ZYDECO. %% All Rights Reserved. %% Disclosure without explicit written consent from the %% copyright owner does not constitute publication. % %% Updated 06-Jul-1998 10:02:02. % %% N.B. -- The following globals are needed %% for persistence, not for global access. % %global theFigureName %global theFigureNumberTitle %global theLineHandle %global theTextHandle %global theMarkerHandle %global mouseDidMove % %DIGITS = 6; % %if nargin < 1, theLine = gcbo; end % %% If not a callback, install "findpt" %% in all the lines in the figure. % %if isempty(gcbo) % if isempty(theLine) % theLine = findobj(gcf, 'Type', 'line'); % end % if any(theLine) % set(theLine, 'ButtonDownFcn', mfilename) % end % return %end % %if nargin == 1 % switch theLine % case 0 % Mouse up. % if any(theTextHandle) % if any(mouseDidMove) % delete(theTextHandle) % delete(theMarkerHandle) % mouseDidMove = 0; % end % set(gcf, 'Name', theFigureName, 'NumberTitle', theFigureNumberTitle) % theLineHandle = []; % theTextHandle = []; % theMarkerHandle = []; % set(gcf, 'Name', theFigureName, ... % 'NumberTitle', theFigureNumberTitle, ... % 'WindowButtonMotionFcn', '', ... % 'WindowButtonUpFcn', '') % theFigureName = ''; % theFigureNumberTitle = ''; % return % end %case -1 % Mouse move. % a = theFigureName; % b = theFigureNumberTitle; % mouseDidMove = 1; % delete(theTextHandle) % delete(theMarkerHandle) % findpt(theLineHandle) % theFigureName = a; % theFigureNumberTitle = b; % return % otherwise % end %end % %switch get(theLine, 'Type') %case 'line' %otherwise % if nargout > 0, theResult = []; end % return %end % %if nargin < 2 % theCurrentPoint = mean(get(gca, 'CurrentPoint')); % Assume "view(2)". % x = theCurrentPoint(1); % y = theCurrentPoint(2); % z = theCurrentPoint(3); %end % %theXRange = diff(get(gca, 'XLim')); %theYRange = diff(get(gca, 'YLim')); %theZRange = diff(get(gca, 'ZLim')); %theZRange = 1; % Assume "view(2)". % %theXData = get(theLine, 'XData'); %theYData = get(theLine, 'YData'); %theZData = get(theLine, 'ZData'); %emptyZ = 0; %if isempty(theZData) % emptyZ = 1; % theZData = zeros(size(theXData)); %end % %theZTemp = theZData .* 0; % Assume "view(2)". % %dx = (theXData - x) .* theYRange .* theZRange; %dy = (theYData - y) .* theXRange .* theZRange; %dz = (theZTemp - z) .* theXRange .* theYRange; % %dd = dx.^2 + dy.^2 + dz.^2; % %theIndex = find(dd == min(dd)); %if any(theIndex), theIndex = theIndex(1); end % %x = theXData(theIndex); %y = theYData(theIndex); %z = theZData(theIndex); % %result = [theLine, theIndex, x, y, z]; % %% N.B. We need to display the z-value (see below) %% if there is any z-data in the line. % %if nargout > 1 % theResult = theLine; %elseif nargout == 1 % theResult = result; %else % assignin('base', 'ans', result) % theString = [num2str(x, DIGITS) ', ' num2str(y, DIGITS)]; % if ~emptyZ % theString = [theString ', ' num2str(z, DIGITS)]; % end % if (1), disp(theString), end % theString = ['<' theString '>']; % theFigureName = get(gcf, 'Name'); % theFigureNumberTitle = get(gcf, 'NumberTitle'); % set(gcf, 'Name', theString, 'NumberTitle', 'off') % theMarker = get(theLine, 'Marker'); % theColor = get(theLine, 'Color'); % switch theMarker % case 'o' % theMarker = '*'; % otherwise % theMarker = 'o'; % end % theLineHandle = theLine; % theMarkerHandle = line(x, y, ... % 'Marker', theMarker, ... % 'EraseMode', 'xor'); % theTextHandle = text(x, y, theString, ... % 'Tag', mfilename, 'EraseMode', 'xor', ... % 'HorizontalAlignment', 'right', ... % 'VerticalAlignment', 'bottom'); % theButtonDownFcn = 'delete(get(gcbo, ''UserData''))'; % h = [theMarkerHandle; theTextHandle]; % set(h, 'UserData', h, 'ButtonDownFcn', theButtonDownFcn) % set(gcf, 'WindowButtonMotionFcn', 'findpt(-1)') % set(gcf, 'WindowButtonUpFcn', 'findpt(0)') %end fclose(fout); disp(' ## Installing: "findstr1.m" (text)') fout = fopen('findstr1.m', 'w'); %function theResult = findstr1(theText, theString) % %% findstr1 -- Find string, using * wildcard. %% findstr('demo') demonstrates itself. %% findstr1('theText', 'theString') searches 'theText' %% for all examples of 'theString', which may include %% one or more asterisks '*' as wildcards, representing %% zero or more characters. The sought-after string may %% also contain escaped characters, preceeded by backslash %% '\', and followed by one of '\bfnrt'. The routine %% returns or displays the indices of the starts of all %% qualifying strings. Not case-sensitive. % %% Copyright (C) 2000 Dr. Charles R. Denham, ZYDECO. %% All Rights Reserved. %% Disclosure without explicit written consent from the %% copyright owner does not constitute publication. % %% Version of 04-Jan-2000 15:13:15. %% Updated 14-Jun-2001 05:35:04. % %% To do: %% %% 1. Need ? wildcard for single character. %% 2. Need $ for end of line. % %if nargout > 0, theResult = []; end % %if nargin < 1, theText = 'demo'; end % %if nargin < 2 & isequal(theText, 'demo') % help(mfilename) % theCommand = [mfilename '(''abracadabra'', ''a*b*a'')']; % disp(theCommand) % disp(mat2str(eval(theCommand))) % return %end % %if size(theText, 2) == 1, theText = theText.'; end %if size(theString, 2) == 1, theString = theString.'; end % %result = []; % %special = '\bfnrt'; %for i = 1:length(special) % s = ['\' special(i)]; % theString = strrep(theString, s, sprintf(s)); %end % %f = find(theString(1:end-1) == '*'); %if any(length(f) > 1) % theString(f(diff(f) == 1)) = ''; %end % %f = find(theString ~= '*'); %if any(f) % theString = theString(f(1):f(end)); %end % %theString = ['*' theString '*']; %stars = find(theString == '*'); % %if all(theString == '*') % result = 1:length(theText); % stars = []; %end % %len = 0; % %for i = 1:length(stars)-1 % s = theString(stars(i)+1:stars(i+1)-1); % len = len + length(s); % f = findstr(theText, s); % if isempty(f) % result = []; % elseif i == 1 % result = f; % elseif any(result) % okay = find(result+len <= max(f)+length(s)); % Careful. % result = result(okay); % end % if isempty(result), break, end %end % %if nargout > 0 % theResult = result; %else % disp(result) %end fclose(fout); disp(' ## Installing: "fixnl.m" (text)') fout = fopen('fixnl.m', 'w'); %function theResult = fixnl(theInputFile, theOutputFile, oldNL, newNL) % %% fixnl -- Fix newline characters. %% fixnl('theInputFile', 'theOutputFile') repairs the %% newline characters in the text file named 'theInputFile' %% and places the result in 'theOutputFile'. If no input %% file is given, the get/put file dialogs are used. %% The name of the output file is returned. The routine %% assumes that the input file uses either CR or LF or %% [CR LF], and that the output file is to conform to %% the current computer's standard newline scheme, namely %% Macintosh = CR, Unix = LF, and PCWIN = [CR LF], where %% CR = char(13); LF = char(10). %% fixnl('theInputFile', 'theOutputFile', 'oldNL', 'newNL') %% uses the given NL strings, rather than the standard ones. %% For example, users may need to convert [CR CR LF] %% to [CR LF], perhaps due to a mistaken translation %% of a file during an Internet transfer. %% fixnl('oldNL', 'newNL') invokes the get/put dialogs %% to get the filenames. % %% Copyright (C) 1997 Dr. Charles R. Denham, ZYDECO. %% All Rights Reserved. %% Disclosure without explicit written consent from the %% copyright owner does not constitute publication. % %% Version of 24-Apr-1997 14:40:37. %% Updated 01-Nov-2002 15:13:52. % %% Get input file. % %if nargin < 1, theInputFile = ''; end %if nargin < 2, theOutputFile = ''; end % %% Default behavior. Use the get/put dialogs. % %if nargin < 1 % while (1) % result = fixnl('', ''); % if isempty(result) % if nargout > 0, theResult = result; end % return % end % end %end % %% User-defined behavior. Use the get/put dialogs. % %if nargin == 2 & ... % any(theInputFile < char(32)) & ... % any(theOutputFile < char(32)) % oldNL = theInputFile; % newNL = theOutputFile; % while (1) % result = fixnl('', '', oldNL, newNL); % if isempty(result) % if nargout > 0, theResult = result; end % return % end % end %end % %% Normal behavior. % %result = ''; % %if isempty(theInputFile) % theInputFilename = 0; % thePrompt = 'Select File To Convert:'; % [theInputFilename, thePathname] = uigetfile('*', thePrompt); % if ~any(theInputFilename) % if nargout > 0, theResult = result; end % return % end % theInputFile = [thePathname theInputFilename]; % else % theInputFilename = theInputFile; %end % %% Get output file. % %if isempty(theOutputFile) % theOutputFile = 0; % theOutputFilename = theInputFilename; % thePrompt = 'Save Converted File As:'; % [theOutputFilename, thePathname] = ... % uiputfile(theInputFilename, thePrompt); % if ~any(theOutputFilename) % if nargout > 0, theResult = result; end % return % end % theOutputFile = [thePathname theOutputFilename]; % else % theOutputFilename = theOutputFile; %end % %if strcmp(theOutputFile, '.') % theOutputFile = theInputFile; %end % %% Read input file. % %fp = fopen(theInputFile, 'r'); %s = setstr(fread(fp).'); %fclose(fp); % %% Save to temporary file if overwriting. % %if strcmp(lower(theOutputFile), lower(theInputFile)) % theSavedFile = [theInputFile '.saved']; % fp = fopen(theSavedFile, 'w'); % theCount = fwrite(fp, s); % fclose(fp); % if theCount ~= length(s) % disp(' ## Unable to save a copy of the input file.') % if nargout > 0, theResult = result; end % return % end %end % %CR = setstr(13); % Carriage-return. %LF = setstr(10); % Line-feed. %CRLF = [CR LF]; % PC and Vax style. % %if nargin < 4 % c = computer; % if findstr(computer, 'MAC') % Macintosh. % NL = CR; % elseif findstr(computer, 'PCWIN') % PC. % NL = CRLF; % elseif findstr(computer, 'VMS') % Vax VMS. % NL = CRLF; % else % Unix. % NL = LF; % end % % f = find(s == LF); % g = find(s == CR); % if any(f) & any(g) & isequal(g+1, f) % s(f) = ''; % end % % f = find(s == LF); % s(f) = CR; % % if ~isequal(NL, CR) % s = strrep(s, CR, NL); % end %else % s = strrep(s, oldNL, newNL); %end % %% Save to output file. % %fp = fopen([theOutputFile], 'w'); %theCount = fwrite(fp, s); %fclose(fp); % %% Delete temporary file. % %result = theOutputFile; % %if strcmp(lower(theOutputFile), lower(theInputFile)) % if theCount == length(s) % delete(theSavedFile) % else % result = ''; % disp(' ## Error during "fixnl" output.') % disp([' ## Original data are in "' theSavedFile '"']) % end %end % %disp([' ## Newlines fixed -- ' theInputFilename ' ==> ' theOutputFilename]) % %if nargout > 0, theResult = result; end fclose(fout); disp(' ## Installing: "fpeval.m" (text)') fout = fopen('fpeval.m', 'w'); %function [varargout] = fpeval(theFcn, varargin) % %% fpeval -- FEVAL by full-path name. %% [...] = fpeval('theFcn', ...) performs FEVAL with %% 'theFcn' function, given by its full-path name, %% exclusive of extension. Use this routine to %% execute functions that lie outside the Matlab %% path, including those hidden in "private" %% areas. %% [...] = fpeval({theFcnParts}, ...) will use the %% Matlab "fullfile" function to construct theFcn %% from a list of its part-names. For example, %% {matlabroot, 'toolbox', 'signal', 'private', %% 'chi2conf'} will reach the private chi-square %% confidence routine in the "signal" toolbox. % %% Copyright (C) 1998 Dr. Charles R. Denham, ZYDECO. %% All Rights Reserved. %% Disclosure without explicit written consent from the %% copyright owner does not constitute publication. % %% Version of 02-Nov-1998 09:43:22. % %if nargin < 1, help(mfilename), return, end % %if iscell(theFcn) % theFcn = fullfile(theFcn{:}); %end % %% Separate directory and function names. % %originalFcn = theFcn; % %thePWD = pwd; %theDir = ''; %f = find(theFcn == filesep); %if any(f) % theDir = theFcn(1:f(end)); % theFcn(1:f(end)) = ''; %end % %% Trim extension, if any. % %f = find(theFcn == '.'); %if any(f), theFcn(f(1):end) = ''; end % %% Change directory, then execute. % %try % if ~isempty(theDir), cd(theDir), end % if nargout > 0 % varargout = cell(1, nargout); % [varargout{:}] = feval(theFcn, varargin{:}); % else % feval(theFcn, varargin{:}); % end %catch % disp([' ## ' mfilename ' -- An error occurred while attempting:']) % disp([' ## "' originalFcn '"']) % disp([' ## ' lasterr]) %end % %% Restore directory, no matter what. % %if ~isempty(theDir), cd(thePWD), end fclose(fout); disp(' ## Installing: "fps.m" (text)') fout = fopen('fps.m', 'w'); %function u = fps(p, isSlope, dx, dy) % %% fps -- Fast Poisson solver with boundary values. %% fps(p) solves laplacian(u) = p for u, assuming the %% boundary values are given along the perimeter of %% p and the laplacians are given in the interior. %% fps(p, isSlope) solves using the perimeter of p %% as values of slope, if isSlope is logically TRUE. %% fps(p, isSlope, dx, dy) uses sample intervals dx %% and dy. Defaults = 1 and 1, respectively. %% fps([m n]) demonstrates itself with an n-by-n array %% (default = [20 20]), with an off-center spike. %% Note: for the speediest Fourier transform, use a p %% whose size is a composite of small factors, then %% add 2, such as 33. %% %% Also see: fpt. % %% Copyright (C) 1998 Dr. Charles R. Denham, ZYDECO. %% All Rights Reserved. %% Disclosure without explicit written consent from the %% copyright owner does not constitute publication. % %% Reference: Press, et al., Numerical Recipes, %% Cambridge University Press, 1986 and later. % %% Version of 23-Oct-1998 09:02:58. %% Updated 15-May-2002 11:11:40. % %if nargin < 1, help(mfilename), p = 'demo'; end %if nargin < 2, isSlope = 0; end %if nargin < 3, dx = 1; end %if nargin < 4, dy = 1; end % %if ischar(isSlope), isSlope = eval(isSlope); end %isSlope == any(isSlope(:)); % %if isequal(p, 'demo'), p = 20; end %if ischar(p), p = eval(p); end %if length(p) == 1 % if nargin < 2 % p(2) = p; % else % p(2) = isSlope; % end %end % %if length(p) == 2 % theSize = max(p, 4); % p = zeros(theSize); % [m, n] = size(p); % p(ceil(m/3), ceil(n/3)) = 1; % feval(mfilename, p, isSlope, dx, dy); % return %end % %if nargout < 1, tic; end % %% Fold the boundary into source terms. % %if ~isSlope % theFactor = -1; % Boundary-value scheme. %else % theFactor = +2; % Boundary-slope scheme. %end % %q = p; %for i = 1:2 % q = q.'; % q(2:end-1, 2:end-3:end-1) = ... % q(2:end-1, 2:end-3:end-1) + ... % theFactor * q(2:end-1, 1:end-1:end); %end % %% Extract the interior. % %q = q(2:end-1, 2:end-1); % %% Symmetry: odd if 'value'; even if 'slope'. % %if ~isSlope % theSign = -1; % Odd-symmetry, sine-transform scheme. %else % theSign = +1; % Even-symmetry, cosine-transform scheme. %end % %[m, n] = size(q); %q = [zeros(m, 1) q zeros(m, 1) theSign*fliplr(q)]; %q = [zeros(1, 2*n+2); q; zeros(1, 2*n+2); theSign*flipud(q)]; % %% Fast Poisson Transform. The array q is now twice the size %% of the original p, minus two elements in each direction. %% Thus, to invoke a power-of-two Fourier transform, use %% sizes that themselves are a power-of-two plus one. % %res = fpt(q, 0, dx, dy); % %% Retain relevant piece. % %if ~isSlope % result = p; % result(2:end-1, 2:end-1) = res(2:m+1, 2:n+1); %else % result = res(1:m+2, 1:n+2); %end % %% Output or plot solution. % %if nargout > 0 % u = result; %else % disp([' ## Elapsed time: ' num2str(toc) ' s.']) % subplot(2, 2, 1), surf(p), axis tight % title('Laplacian Data'), xlabel('x'), ylabel('y'), zlabel('p') % subplot(2, 2, 2), surf(result), axis tight % title('Poisson Solution'), xlabel('x'), ylabel('y'), zlabel('u') % subplot(2, 2, 3), plot(p), axis tight % xlabel('x'), ylabel('p') % subplot(2, 2, 4), plot(result), axis tight % xlabel('x'), ylabel('u') % figure(gcf) % [m, n] = size(p); % set(gcf, 'Name',[mfilename ' ' int2str(m) ' ' int2str(n)]) % error_norm = norm(4*del2(result(2:end-1, 2:end-1))-p(2:end-1, 2:end-1)); % disp([' ## Error norm: ' num2str(error_norm)]) %end fclose(fout); disp(' ## Installing: "fpt.m" (text)') fout = fopen('fpt.m', 'w'); %function u = fpt(p, doInverse, dx, dy) % %% fpt -- Fast Poisson transform. %% fpt(p) solves laplacian(u) = p, for matrix u, %% assuming periodic boundary conditions. %% fpt(p, doInverse) performs the inverse-transform %% if "doInverse" is logically TRUE. Default = %% FALSE. %% fpt(p, doInverse, dx, dy) uses sample intervals %% dx and dy. Defaults = 1 and 1, respectively. %% %% Also see: fps, fft2, ifft2. % %% Copyright (C) 1998 Dr. Charles R. Denham, ZYDECO. %% All Rights Reserved. %% Disclosure without explicit written consent from the %% copyright owner does not constitute publication. % %% Reference: Press, et al., Numerical Recipes, %% Cambridge University Press, 1986 and later. % %% Version of 23-Oct-1998 09:02:58. %% Updated 10-Feb-2000 20:51:38. % %if nargin < 1, help(mfilename), return, end %if nargin < 2, doInverse = 0; end %if nargin < 3, dx = 1; end %if nargin < 4, dy = 1; end % %% Compute Fourier weights. % %[m, n] = size(p); % %i = (0:m-1).' * ones(1, n); %j = ones(m, 1) * (0:n-1); % %% The simple formula for unit sample intervals is: % %% weights = 2 * (cos(2*pi*i/m) + cos(2*pi*j/n) - 2); % %% We modify it with the actual dx and dy values, %% where dx runs horizontally and dy runs vertically. % %dx2 = dx*dx; %dy2 = dy*dy; %weights = 2 * (cos(2*pi*i/m)/dy2 + cos(2*pi*j/n)/dx2 - 1/dy2 - 1/dx2); %weights(1, 1) = 1; % %% Solve. % %if ~any(doInverse) % u = ifft2(fft2(p) ./ weights); %else % u = ifft2(fft2(p) .* weights); %end % %if isreal(p), u = real(u); end fclose(fout); disp(' ## Installing: "frot13.m" (text)') fout = fopen('frot13.m', 'w'); %function theResult = frot13(theSource, theDestination) % %% frot13 -- ROT13 applied to a file. %% frot13('demo') risks suicide by operating on itself %% twice in succession. %% frot13('theSource', 'theDestination') performs ROT13 %% on the contents of the 'theSource' file and saves the %% result as the 'theDestination' file, which defaults %% to the name of the source-file. If either filename %% contains a '*' wildcard, the appropriate UIGETFILE/ %% UIPUTFILE dialog is invoked. Additionally, if the %% source filename contains a wildcard, the procedure %% is applied repeatedly until the UIGETFILE dialog %% is cancelled. ROT13 is its own inverse. %% frot13 (no argument) same as frot13('*'). % %% Copyright (C) 2000 Dr. Charles R. Denham, ZYDECO. %% All Rights Reserved. %% Disclosure without explicit written consent from the %% copyright owner does not constitute publication. % %% Version of 26-Apr-2000 07:47:15. %% Updated 26-Apr-2000 08:26:35. % %if nargout > 0, theResult = 0; end %if nargin < 1, theSource = '*'; help(mfilename), end % %if isequal(theSource, 'demo') % fp = fopen(which(mfilename), 'r'); % before = fread(fp); % fclose(fp); % mlock % for i = 1:2 % disp([' ## ' upper(mfilename) ' Demo Round No. ' int2str(i)]) % feval(mfilename, which(mfilename)) % end % munlock % fp = fopen(which(mfilename), 'r'); % after = fread(fp); % fclose(fp); % if isequal(before, after) % disp([' ## ' upper(mfilename) ' Demo Successful.']) % else % disp([' ## ' upper(mfilename) ' Demo NOT Successful.']) % end % return %end % %if any(theSource == '*') % theFilter = theSource; % theFile = -1; % while any(theFile) % [theFile, thePath] = uigetfile(theFilter, 'Select File For ROT13'); % if ~any(theFile), status = -1; return, end % if thePath(end) ~= filesep, thePath(end+1) = filesep; end % theSource = [thePath theFile]; % if nargin < 2 % result = feval(mfilename, theSource); % else % result = feval(mfilename, theSource, theDestination); % end % end % if nargout > 0, theResult = result; end % return %end % %if nargin < 2 % theDestination = theSource; %elseif any(theDestination == '*') % theFilter = theDestination; % [theFile, thePath] = uiputfile(theFilter, 'Save ROT13 File As') % if ~any(theFile) % if nargout > 0, theResult = -1; end % return % end % if thePath(end) ~= filesep, thePath(end+1) = filesep; end % theDestination = [thePath theFile]; %end % %result = -1; % %fp = fopen(theSource, 'r'); %if fp >= 0 % s = fread(fp); % result = fclose(fp); %end % %r = rot13(s); % %result = -1; % %fp = fopen(theDestination, 'w'); %if fp >= 0 % fwrite(fp, r); % result = fclose(fp); %end % %if nargout > 0, theResult = result; end % % %% ---------- rot13 ---------- % % %function theResult = rot13(theString) % %% rot13 -- Apply "rot13" 13-letter shift to a string. %% rot13('theString') rotates the alphabetic characters %% in theString by 13 characters. Thus, the string %% 'aAnN' goes to 'nNaA'. Non-alphabetic characters %% are not affected. This routine is its own inverse. %% ROT13 is a lightweight encryption scheme used by %% Internet news-groups to obscure text that might %% be considered offensive to some readers. %% rot13 (no argument) demonstrates itself. % %% Copyright (C) 1997 Dr. Charles R. Denham, ZYDECO. %% All Rights Reserved. %% Disclosure without explicit written consent from the %% copyright owner does not constitute publication. % %% Version of 25-Feb-1998 17:18:21. % %if nargin < 1 % help(mfilename) % before = 'Hello World'; % after = rot13(before); % again = rot13(after); % disp([' ## ROT13: ' before ' ==> ' after ' ==> ' again]) % return %end % %s = theString; % %f = find((s >= 'A' & s <= 'M') | (s >= 'a' & s <= 'm')); %g = find((s >= 'N' & s <= 'Z') | (s >= 'n' & s <= 'z')); % %s(f) = s(f) + 13; %s(g) = s(g) - 13; % %if nargout > 0 % theResult = s; %else % disp(s) %end fclose(fout); disp(' ## Installing: "fsearch.m" (text)') fout = fopen('fsearch.m', 'w'); %function fsearch(theString, varargin) % %% fsearch -- String search in files. %% fsearch (no argument) demonstrates itself by %% searching for the word "demo" in its own %% M-file. %% fsearch('theString') searches recursively by invoking %% fsearch('theString', '*', '-r'). %% fsearch('theString', 'file1', 'file2', ...) searches %% just the given files, as interpreted by the Matlab %% "which" function. Names wildcarded with asterisks (*) %% are interpreted by the Matlab "dir" and "which" functions. %% fsearch(..., 'option1', option2', ...) applies the given %% options (must be at end of argument list). %% Options: '-r' as final argument causes recursive %% search, starting at the current directory. %% Also see help on: dir, findstr, which % %% Copyright (C) 2000 Dr. Charles R. Denham, ZYDECO. %% All Rights Reserved. %% Disclosure without explicit written consent from the %% copyright owner does not constitute publication. % %% Version of 01-Jan-2000 11:27:57. %% Updated 14-Apr-2003 16:19:38. % %% Note: we need to address the "." and ".." problem %% that arises during recursive calls to this function. %% My "dirsafe" function is only part of the solution. % %persistent LEVEL %persistent FOUND % %if nargin < 1 % help(mfilename) % s = 'fsearch(''demo'', ''fsearch.m'')'; % disp(s) % eval(s) % return %end %if nargin < 2, varargin = {'*', '-r'}; end % %if isempty(LEVEL), LEVEL = 0; end %if isempty(FOUND), FOUND = ~~0; end % %CR = char(13); %LF = char(10); %CRLF = [CR LF]; % %isRecursive = ~~0; %if isequal(varargin{end}, '-r') % isRecursive = ~~1; % varargin(end) = []; % if isempty(varargin), varargin = {'*'}; end %end % %for k = 1:length(varargin) % theFiles = varargin{k}; % isWildcard = any(theFiles == '*'); % if isWildcard % d = dirsafe(theFiles); % Need to be careful here. % f = []; % for i = 1:length(d) % if ~d(i).isdir % f{end+1} = d(i).name; % elseif isRecursive % end % end % theFiles = f; % else % theFiles = varargin(k); % end % for j = 1:length(theFiles) % theFileName = theFiles{j}; % if any(theFileName) % theFilePath = which(theFileName); % fp = fopen(theFileName, 'r'); % if fp >= 0 % t = char(fread(fp)).'; % fclose(fp); % t = strrep(t, CRLF, CR); % t = strrep(t, LF, CR); % t(end+1) = CR; % t = [CR t]; % s = lower(t); % theStr = lower(theString); % if any(theStr == '*') % theStr = [theStr '*' CR]; % How to restrict this? % end % pos = findstr1(s, theStr); % Note "findstr1". % if any(pos) % eol = findstr1(s, CR); % before = eol(1:end-1); % after = eol(2:end); % thePrecision = ceil(log10(max(after))); % prev = 0; % for i = 1:length(pos) % f = find(pos(i) > eol(1:end-1) & ... % pos(i) < eol(2:end)); % if any(f) & f > prev % prev = f; % FOUND = ~~1; % theLine = int2str(f); % while length(theLine) < thePrecision % theLine = [' ' theLine]; % end % theText = t(before(f)+1:after(f)-1); % f = find(theText > ' '); % if any(f), theText = theText(f(1):f(end)); end % disp([' ## File "' theFilePath '"; Line ' theLine ' ## ' theText]) % end % end % end % else % disp([' ## Unable to open: ' theFileName]) % end % end % end % if isRecursive % d = dirsafe; % for i = 1:length(d) % if d(i).isdir % thePWD = pwd; % LEVEL = LEVEL+1; % try % cd(d(i).name) % feval(mfilename, theString, varargin{k}, '-r') % catch % disp([' ## Error while processing:']) % disp(theFiles(:)) % end % cd(thePWD) % LEVEL = LEVEL-1; % end % end % end %end % %if LEVEL <= 0 % if ~FOUND, disp([' ## None found.']), end % LEVEL = []; % FOUND = []; %end % % %% ---------- findstr1 ---------- % % % %function theDir = dirsafe(varargin) % %% dirsafe -- DIR which ignores "." and ".." %% dirsafe(...) calls "dir", then removes references %% to the "." and ".." directories, if any. % %% Copyright (C) 2002 Dr. Charles R. Denham, ZYDECO. %% All Rights Reserved. %% Disclosure without explicit written consent from the %% copyright owner does not constitute publication. % %% Version of 18-Sep-2002 16:26:23. %% Updated 18-Sep-2002 16:26:23. % %if nargin < 1 % d = dir; %else % d = dir(varargin{:}); %end % %for i = length(d):-1:1 % if d(i).isdir & all(d(i).name == '.') % d(i) = []; % end %end % %if nargout > 0 % theDir = d; %else % assignin('caller', 'ans', d) % disp(d) %end % % %% ---------- findstr1 ---------- % % % %function theResult = findstr1(theText, theString) % %% findstr1 -- Find string, using * wildcard. %% findstr('demo') demonstrates itself. %% findstr1('theText', 'theString') searches 'theText' %% for all examples of 'theString', which may include %% one or more asterisks '*' as wildcards, representing %% zero or more characters. The sought-after string may %% also contain escaped characters, preceeded by backslash %% '\', and followed by one of '\bfnrt'. The routine %% returns or displays the indices of the starts of all %% qualifying strings. Not case-sensitive. % %% Copyright (C) 2000 Dr. Charles R. Denham, ZYDECO. %% All Rights Reserved. %% Disclosure without explicit written consent from the %% copyright owner does not constitute publication. % %% Version of 04-Jan-2000 15:13:15. %% Updated 04-Jan-2000 21:34:49. % %if nargout > 0, theResult = []; end % %if nargin < 1, theText = 'demo'; end % %if nargin < 2 & isequal(theText, 'demo') % help(mfilename) % theCommand = [mfilename '(''abracadabra'', ''a*b*a'')']; % disp(theCommand) % disp(mat2str(eval(theCommand))) % return %end % %if size(theText, 2) == 1, theText = theText.'; end %if size(theString, 2) == 1, theString = theString.'; end % %special = '\bfnrt'; %for i = 1:length(special) % s = ['\' special(i)]; % theString = strrep(theString, s, sprintf(s)); %end % %while any(findstr(theString, '**')) % theString = strrep(theString, '**', '*'); %end % %f = find(theString ~= '*'); %if any(f) % theString = theString(f(1):f(end)); %end % %theString = ['*' theString '*']; %stars = find(theString == '*'); % %result = []; %len = 0; % %for i = 1:length(stars)-1 % s = theString(stars(i)+1:stars(i+1)-1); % len = len + length(s); % f = findstr(theText, s); % if isempty(f) % result = []; % elseif i == 1 % result = f; % elseif any(result) % okay = find(result+len <= max(f)+length(s)); % Careful. % result = result(okay); % end % if isempty(result), break, end %end % %if nargout > 0 % theResult = result; %else % disp(result) %end fclose(fout); disp(' ## Installing: "genetic.m" (text)') fout = fopen('genetic.m', 'w'); %function [theResult, theFinalCost, theInitialCost] = ... % genetic(theFcn, theParameters, theOptions, empty, varargin) % %% genetic -- Genetic optimization driver. %% genetic('demo') demonstrates itself with 10 parameters. %% genetic(N) demonstrates itself with N parameters (default = 10). %% The procedure combines random vectors genetically, thereby %% redistributing their elements, in hopes of reducing the %% standard-deviation of each vector. The procedure uses %% 3*N parents, 30*N children, 100 iterations, and 0.0001 %% tolerance. %% genetic('theFcn', theParameters, theOptions, [], varargin) minimizes %% theFcn cost-function, using theParameters, a two-column array %% of [xmin xmax], the permitted ranges. TheOptions vector is: %% [#-of-parents; #-of-children; maximum-iterations; maximum-cost]. %% The cost-function will be called repeatedly, using all of the %% evolving parameters at once, followed by the "varargin" arguments, %% if any, until halted by reaching the maximum number of iterations %% or by falling below maximum-cost. (The probabilistic genetic %% actions take place in the "breed" function.) The Fcn input %% is one array, whose columns represent individual solutions, %% plus any additional arguments specified by "varargin". % %% Copyright (C) 2001 Dr. Charles R. Denham, ZYDECO. %% All Rights Reserved. %% Disclosure without explicit written consent from the %% copyright owner does not constitute publication. % %% Version of 29-Mar-2001 17:08:53. %% Updated 14-Jun-2001 07:26:58. % %if nargin < 1 % help(mfilename) % theFcn = 'demo'; %end % %if isequal(theFcn, 'demo') % theFcn = 10; %end % %if nargin < 2 & ischar(theFcn) % theFcn = eval(theFcn); %end % %if ~ischar(theFcn) % nParameters = theFcn(1); % nParents = 3*nParameters; % nChildren = 10*nParents; % if length(theFcn) > 1 % nParents = theFcn(2); % end % if length(theFcn) > 2 % nChildren = theFcn(3); % end % theFcn = 'std'; % theParameters = zeros(nParameters, 2); % theParameters(:, 2) = 1; % theMaximumIterations = 100; % theMaximumCost = 1e-4; % theOptions = [nParents; nChildren; theMaximumIterations; theMaximumCost]; % tic % [result, theFinalCost, theInitialCost] = ... % feval(mfilename, theFcn, theParameters, theOptions); % t = toc; % disp([' ## Elapsed time: ' num2str(ceil(10*t)/10) ' s.']) % hold off % plot(1:length(theFinalCost), theFinalCost, '-bo', ... % 1:length(theInitialCost), theInitialCost, '-ro') % xlabel('Index') % ylabel('Standard-deviation') % legend final initial % set(gca, 'XLim', [0 length(theFinalCost)+1]) % set(gcf, 'Name', ['Genetic ' int2str(nParameters)]) % return %end % %nParents = theOptions(1); %nChildren = theOptions(2); %theMaximumIterations = theOptions(3); %theMaximumCost = theOptions(4); % %[m, n] = size(theParameters); %nParameters = m; % %sz = [1 nParents+nChildren]; %xmin = repmat(theParameters(:, 1), sz); %xmax = repmat(theParameters(:, 2), sz); %xdif = xmax - xmin; % %xmin_p = xmin(:, 1:nParents); %xdif_p = xmax(:, 1:nParents) - xmin(:, 1:nParents); %xmin_c = xmin(:, 1:nChildren); %xdif_c = xmax(:, 1:nChildren) - xmin(:, 1:nChildren); % %xval = rand(nParameters, nParents) .* xdif_p + ... % xmin_p; % %% Evaluate the parents. % %if isempty(varargin) % theInitialCost = feval(theFcn, xval); %else % theInitialCost = feval(theFcn, xval, varargin{:}); %end % %% Breed many generations by genetic-crossover %% of the parameter-vectors. Once debugged, %% we will add a small amount of genetic-drift, %% to the mix, plus an even smaller amount of %% gross genetic-mutation. % %% Need to trap invalid costs, such as NaN or negative. % %iter = 0; %cost = theInitialCost; % %while iter < theMaximumIterations & all(cost > theMaximumCost) % if iter > 0 & rem(iter, 100) == 0 % disp([' ## iter: ' int2str(iter)]) % cost % end % iter = iter+1; % xval = (xval(:, 1:nParents) - xmin(:, 1:nParents)) ./ ... % xdif(:, 1:nParents); % xnew = breed(xval, nChildren); % if (0) % xnew = drift(xnew); % xnew = mutate(xnew); % end % xnew = xnew .* xdif(:, 1:nChildren) + ... % xmin(:, 1:nChildren); % if isempty(varargin) % newCost = feval(theFcn, xnew); % else % newCost = feval(theFcn, xnew, varargin{:}); % end % %% hello %% xnew %% newCost % %% We need to compute a fitness, then use %% it as the probability of survival. % %% hello % cost = [cost newCost]; % xval = [xval xnew]; % % fitness = exp(-cost); % cumulative = cumsum(fitness); % cumulative = cumulative ./ cumulative(end); % Normalize. % cumulative(end) = 1; % % index = zeros(size(cumulative)); % %% The following features a "while" loop that %% protects the search-scheme, until we discover %% how to make it bullet-proof. We want "f" never %% to be empty. % % okay = ~~0; % while ~okay % okay = ~~1; % r = sort(rand(size(cumulative))); % for i = 1:length(r) % f = find(r(i) <= cumulative); % Very slow: 40% % if isempty(f) % okay = ~~0; % break % else % index(i) = f(1); % end % end % end %% hello %% index % f = find(diff(index) == 0); % if any(f) % index(f) = []; % end % %% hello %% index %% cost % % cost = cost(index); % xval = xval(:, index); % % % hello % [cost, index] = sort(cost); % % xval = xval(:, index); % xval = xval(:, 1:nParents); % cost = cost(1:nParents); %end % %if nargout > 0 % theResult = xval; % theFinalCost = cost; %else % result = xval % cost %end % % %% ---------- breed ---------- % % % %function progeny = breed(parents, nChildren) % %% breed -- Parents breed children. %% breed(parents, nChildren) breds nChildren from %% the given parents. % %DRIFT_PROB = 1e-4; % See the "drift" function below. %DRIFT_AMOUNT = 1e-4; % See the "drift" function below. %MUTATE_PROB = 1e-4; % See the "mutate" function below. % %[m, n] = size(parents); %progeny = zeros(m, nChildren); %for i = 1:2:nChildren % k = floor(rand(1, 2) .* n + 1); % progeny(:, [i i+1]) = crossover(parents(:, k)); % Slow: 10% %end %progeny = drift(progeny, DRIFT_PROB, DRIFT_AMOUNT); %progeny = mutate(progeny, MUTATE_PROB); % % %% ---------- crossover ---------- % % % %function y = crossover(x) % %% crossover -- Genetic crossover. %% crossover(x) combines the two columns of x %% by genetic crossover. % %[m, n] = size(x); % %i = (rand(m, 1) < 0.5); %j = ~i; % %y = zeros(size(x)); %y(:, 1) = x(:, 1) .* i + x(:, 2) .* j; % Slow: 8% %y(:, 2) = x(:, 1) .* j + x(:, 2) .* i; % Slow: 8% % % %% ---------- drift ---------- % % % %function y = drift(x, prob, amount) % %% drift -- Genetic drift by small amounts. %% drift(x, prob, amount) adds genetic-drift %% to the columns of x, by the given small %% probability, in the given amount. % %if nargin < 2, prob = 1e-4; end %if nargin < 3, amount = 1e-4; end % %r = rand(size(x)); %s = 2 * (rand(size(x)) - 0.5); %y = x; %y(r < prob) = y(r < prob) + s(r < prob) .* amount; %y = max(min(y, 1), 0); % % %% ---------- mutate ---------- % % % %function y = mutate(x, prob) % %% mutate -- Genetic mutation by small probabilities. %% mutate(x, prob) mutates the columns of x by the %% given small probability. % %if nargin < 2, prob = 1e-4; end % %r = rand(size(x)); %s = rand(size(x)); %y = x; %y(r < prob) = s(r < prob); fclose(fout); disp(' ## Installing: "geo_simplify.m" (text)') fout = fopen('geo_simplify.m', 'w'); %function [olon, olat] = geo_simplify(lon, lat, frac, nmin) % %% geo_simplify -- NaN-aware driver for geo_simp. %% [olon, olat] = geo_simplify(lon, lat, frac, nmin) calls %% geo_simp independently for each of the NaN-separated %% segments of the (lon, lat) data. The concatenated results %% are returned as (olon, olat). The proportion to be kept %% in the result is given by frac (default = 0.5), a decimal %% fraction between 0 and 1. Nmin (default = 4) specifies %% the smallest segment of the result that will be retained. %% [out] = ... returns the result as one array of [olon olat]. %% geo_simplify(N) demonstrates itself for N points (default = 24), %% containing a NaN in the middle. The result preserves about %% one-third of the original points. % %% Copyright (C) 1999 Dr. Charles R. Denham, ZYDECO. %% All Rights Reserved. %% Disclosure without explicit written consent from the %% copyright owner does not constitute publication. % %% Version of 08-Feb-1999 15:57:00. %% Updated 09-Feb-1999 10:44:56. %% Updated 11-Feb-1999 14:12:56. % %if nargin < 1, help(mfilename), lon = 'demo'; end % %if isequal(lon, 'demo'), lon = 24; end % %if ischar(lon), lon = eval(lon); end % %if length(lon) == 1 % n = lon; % lon = (1:n).'; % lat = cumsum(rand(size(lon))-0.5) .* 10; % lat(ceil(n/2)) = NaN; % frac = 1/3; % nmin = 1; % tic % [lon1, lat1] = geo_simplify(lon, lat, frac); % toc % plot(lon1, lat1, '-*', lon, lat, 'o') % xlabel('lon (degrees)'), ylabel('lat (degrees)') % title('geo\_simplify') % axis equal % set(gcf, 'Name', 'geo_simplify') % figure(gcf) % return %end % %if nargin < 3, frac = 0.5; end %if nargin < 4, nmin = 4; end % %f = find(~isfinite(lon) | ~isfinite(lat)); %f = [0; f; length(lon)+1]; % %lon1 = []; %lat1 = []; %for k = 2:length(f) % i = f(k-1)+1; % j = f(k)-1; % count = j - i + 1; % if count >= nmin % [lo, la] = geo_simp(lon(i:j), lat(i:j), frac); % if length(lo) >= nmin % lon1 = [lon1; lo; NaN]; % lat1 = [lat1; la; NaN]; % end % end %end % %if nargout == 1 % olon = [lon1 lat1]; %elseif nargout > 1 % olon = lon1; % olat = lat1; %else % disp([lon1 lat1]); %end % %function [olon, olat] = geo_simp(lon, lat, nmax, tolerance) % %% geo_simp -- Simplify a (lon, lat) contour. %% [olon, olat] = geo_simp(lon, lat, nmax, tolerance) %% simplifies the (lon, lat) contour, returning nmax points %% if (nmax > 0), or those points that are more significant %% than the given tolerance. The gs_sort() routine is used, %% in which the deviation, not the curvature, is the key %% principle. NaNs are ignored. Nmax may be specified as %% a decimal fraction (0...1), or as an integer > 1. %% [out] = geo_simplity(...) returns [olon olat] in one array. %% geo_simplify(nPoints) demonstrates itself with nPoints %% (random); default = 24. % %% Copyright (C) 1997 Dr. Charles R. Denham, ZYDECO. %% All Rights Reserved. %% Disclosure without explicit written consent from the %% copyright owner does not constitute publication. % %% Version of 06-Jul-1998 06:40:26. %% Revised 04-Sep-1998 15:29:19. % %% Reference: Douglas, D.H. and T.K. Peucker, Algorithms for %% the reduction of the number of points required to represent %% a digitized line of (sic?) its caricature, Can. Cartogr., %% 10, 112-122, 1973. We have adopted a similar scheme for %% selecting "significant" points. Unlike the D-P algorithm, %% we sort all the points first, then isolate those that satisfy %% our criteria for tolerance or total number of points retained. % %if nargin < 1, help(mfilename), lon = 'demo'; end % %if isequal(lon, 'demo'), lon = 24; end % %if ischar(lon), lon = eval(lon); end % %if length(lon) == 1 % n = lon; % lon = 1:n; % lat = cumsum(rand(size(lon))-0.5) .* 10; % lat(ceil(n/2)) = NaN; % nmax = fix((n+2) ./ 3); % tolerance = 0; % tic % [lon1, lat1] = geo_simp(lon, lat, nmax, tolerance); % toc % plot(lon1, lat1, '-*', lon, lat, 'o') % xlabel('lon (degrees)'), ylabel('lat (degrees)') % title('geo\_simp') % axis equal % set(gcf, 'Name', 'geo_simp') % figure(gcf) % return %end % %if nargin < 3, nmax = length(lon); end %if nargin < 4 % tolerance = 0; % if nmax == 0, nmax = length(lon); end %end % %if nmax > 0 & nmax <= 1 % nmax = round(nmax*length(lon)); %end % %RCF = 180 ./ pi; %x = cos(lat/RCF).*cos(lon/RCF); %y = cos(lat/RCF).*sin(lon/RCF); %z = sin(lat/RCF); % %% Save NaNs. % %xx = x(:); %yy = y(:); %zz = z(:); % %i = find(isfinite(xx) & isfinite(yy) & isfinite(zz)); %j = find(~isfinite(xx) | ~isfinite(yy) | ~isfinite(zz)); %if any(i), xx = xx(i); yy = yy(i); zz = zz(i); end % %% Sort. % %[ind, dev] = gs_sort(xx, yy, zz); % %% Restore NaNs. % %ind = i(ind); %ind = [ind; j(:)]; %dev = [dev; NaN*j]; % %% Deviation angle: always < 90 degrees. % %dev = asin(dev) .* 180 ./ pi; % %% Trim by count or tolerance. % %if nmax > 0 % if nmax <= 1, nmax = round(nmax .* length(lon)); end % nmax = max(3, min(nmax, length(lon))); % ind = ind(1:nmax); % dev = dev(1:nmax); %else % f = find(dev >= tolerance); % if any(f) % ind = ind(f); % dev = dev(f); % end %end % %% Unsort. % %[ind, s] = sort(ind); %dev = dev(s); % %lon1 = lon(ind); %lat1 = lat(ind); % %if nargout == 1 % olon = [lon1 lat1]; %elseif nargout > 1 % olon = lon1; % olat = lat1; %end % %function [theIndices, theDeviations] = gs_sort(x, y, z) % %% gs_sort -- Sort (x, y, z) data for line-simplification. %% [theIndices, theDeviations] = gs_sort(x, y, z) returns %% indices and deviations of the given (x, y, z) data, %% in order of decreasing importance. The (x, y, z) %% data are geographic, expressed as direction-cosines. %% The deviations are the sines of the angles of %% deviation. % %% Copyright (C) 1997 Dr. Charles R. Denham, ZYDECO. %% All Rights Reserved. %% Disclosure without explicit written consent from the %% copyright owner does not constitute publication. % %% Version of 02-Jul-1998 09:36:15. % %if nargin < 1, help(mfilename), x = 'demo'; end % %if isequal(x, 'demo'), x = 24; end % %if ischar(x), x = eval(x); end % %if length(x) == 1 % n = x; % a = cumsum(rand(n, 3)-0.5); % for i = 1:n % a(i, :) = a(i, :) ./ norm(a(i, :)); % end % x = a(:, 1); y = a(:, 2); z = a(:, 3); % tic % [i, d] = gs_sort(x, y, z); % toc % reduce = 3; % Reduction-factor. % k = fix((n+reduce-1)./reduce); % ii = i(1:k); % dd = d(1:k); % xx = x(ii); % yy = y(ii); % zz = z(ii); % [ii, s] = sort(ii); % dd = dd(s); % xx = xx(s); % yy = yy(s); % zz = zz(s); % subplot(2, 1, 1) % plot3(x, y, z, 'b+', xx, yy, zz, 'go-') % title('Data and Subset') % xlabel('x'), ylabel('y'), zlabel('z') % view(2) % subplot(2, 1, 2) % plot(i, d, '.', xx, dd, 'o') % title('Deviation') % xlabel('x'), ylabel('y'), zlabel('z') % view(2) % set(gcf, 'Name', 'gs_sort demo') % figure(gcf) % return %end % %ind = zeros(size(x)); %dev = zeros(size(x)); % %nstack = ceil(1 + 2*log(length(x))/log(2)); %stack = zeros(nstack, 2); %nstack = 1; %stack(nstack, :) = [1 length(x)]; % %ind(1) = 1; %ind(2) = length(x); %nout = 2; % %% Call gs_pivot() repeatedly and stack the %% longer interval before the shorter. % %while nstack > 0 % a = stack(nstack, 1); % b = stack(nstack, 2); % nstack = nstack - 1; % if b-a > 1 % [p, d] = gs_pivot(x([a:b]), y([a:b]), z([a:b])); % if any(p) % p = a+p-1; % nout = nout+1; % ind(nout) = p; % dev(nout) = d; % if b-p >= p-a % if b-p > 1 % nstack = nstack + 1; % stack(nstack, :) = [p b]; % end % end % if p-a > 1 % nstack = nstack + 1; % stack(nstack, :) = [a p]; % end % if b-p < p-a % if b-p > 1 % nstack = nstack + 1; % stack(nstack, :) = [p b]; % end % end % end % end %end % %% Sort in descending order of importance. % %dev(1:2) = max(dev); %[ignore, s] = sort(-dev); %ind = ind(s); %dev = dev(s); % %% Output. % %if nargout > 0 % theIndices = ind; % theDeviations = dev; %else % ind, dev %end % %function [thePivot, theDeviation] = gs_pivot(x, y, z) % %% gs_pivot -- Geographic line-simplification pivot. %% [thePivot, theDeviation] = gs_pivot(x, y, z) returns %% the index of the (x, y, z) point that deviates most %% from the great-circle path between the first and last %% of the geographic points, given as direction-cosines. %% Only finite points are allowed. The deviation is %% returned as the sine of the deviation-angle. % %% Copyright (C) 1997 Dr. Charles R. Denham, ZYDECO. %% All Rights Reserved. %% Disclosure without explicit written consent from the %% copyright owner does not constitute publication. % %% Version of 02-Jul-1998 08:32:40. % %if nargin < 1, help(mfilename), x = 'demo'; end % %if isequal(x, 'demo'), x = 10; end % %if ischar(x), x = eval(x); end % %if length(x) == 1 % n = x; % a = cumsum(rand(n, 3)-0.5); % for i = 1:n % a(i, :) = a(i, :) ./ norm(a(i, :)); % end % x = a(:, 1); y = a(:, 2); z = a(:, 3); % tic % [piv, dev] = gs_pivot(x, y, z) % toc % plot3(x, y, z, 'b-', ... % x([1 n]), y([1 n]), z([1, n]), 'g-', ... % x(piv), y(piv), z(piv), 'r*') % title(['gs\_pivot(' int2str(n) ')']) % xlabel('x'), ylabel('y'), zlabel('z') % set(gca, 'Box', 'on') % figure(gcf) % return %end % %thePivot = 0; %theDeviation = -inf; % %n = length(x); %if n < 3, return, end % %% Pole of the spanning great-circle. %% WARNING: no such pole will exist if the two %% end-points are the same. In that case, use %% point farthest from the ends. % %if any([x(1) y(1) z(1)] ~= [x(n) y(n) z(n)]) % c(1) = y(1)*z(n)-y(n)*z(1); % c(2) = z(1)*x(n)-z(n)*x(1); % c(3) = x(1)*y(n)-x(n)*y(1); % c = c.' ./ norm(c); % d = [x y z] * c; %else % c = [x(1) y(1) z(1)].'; % d = [x y z] * c; % d = sqrt(1 - d.*d); %end % %% Find the pivot and deviation. % %temp = abs(d(2:n-1)); %f = find(temp == max(temp)); % %piv = f(1) + 1; %dev = abs(d(piv)); % %% Output. % %if nargout > 0 % thePivot = piv; % theDeviation = dev; %else % piv, dev %end fclose(fout); disp(' ## Installing: "getinfo.m" (text)') fout = fopen('getinfo.m', 'w'); %function [theResult, isOkay] = getinfo(theInfo, theField) % %% getinfo -- Get field value from an "Info" struct. %% getinfo(theInfo, 'theField') returns the current %% value of 'theField' in theInfo, a struct that %% is compatible with the "uigetinfo" function. %% Non-existent fields return the empty-matrix. %% [theResult, isOkay] = ... returns isOkay = 0 %% if an error occurred; otherwise, non-zero. %% getinfo(theInfo) returns a struct containing %% the fields and current selections of theInfo. % %% Copyright (C) 1997 Dr. Charles R. Denham, ZYDECO. %% All Rights Reserved. %% Disclosure without explicit written consent from the %% copyright owner does not constitute publication. % %% Version of 07-Feb-1998 09:45:56. %% Updated 14-Nov-2001 15:07:51. % %if nargout > 0, theResult = []; end %if nargin < 1, help(mfilename), return, end % %% Get current selections, recursively if needed. % %if nargin < 2 % result = theInfo; % theFields = fieldnames(result); % isOkay = 1; % for i = 1:length(theFields) % [theValue, okay] = getinfo(theInfo, theFields{i}); % isOkay = isOkay & okay; % switch class(theValue) % case 'struct' % [res, okay] = getinfo(theValue); % isOkay = isOkay & okay; % result = setfield(result, theFields{i}, res); % otherwise % result = setfield(result, theFields{i}, theValue); % end % end % if nargout > 0 % theResult = result; % else % disp(result) % end % return %end % %% Note: Matlab 6+ does not allow "getfield(a, 'b.c')", %% unlike previous versions. We need to parse the %% 'b.c' ourselves, then call "getfield(a, 'b', 'c')". % %if ischar(theField) & any(theField == '.') % theField = [theField '.']; % f = find(theField == '.'); % theParts = cell(1, length(f)); % k = 0; % for i = 1:length(f) % theParts{i} = theField(k+1:f(i)-1); % k = f(i); % end % % theField = theParts; %elseif ~iscell(theField) % theField = {theField}; %end % %theValue = []; % %isOkay = 1; %% eval('theValue = getfield(theInfo, theField);', 'isOkay = 0;'); %eval('theValue = getfield(theInfo, theField{:});', 'isOkay = 0;'); % %result = theValue; % %if all(isOkay) % switch class(theValue) % case 'cell' % if isequal(theValue{1}, 'checkbox') | ... % isequal(theValue{1}, 'radiobutton') % if length(theValue) < 2, theValue{2} = 0; end % result = theValue{2}; % else % if ~iscell(theValue{1}), theValue = {theValue{1}}; end % if length(theValue) < 2, theValue{2} = 1; end % result = theValue{1}{theValue{2}}; % end % otherwise % result = theValue; % end %end % %if nargout > 0 % theResult = result; %else % disp(result) %end fclose(fout); disp(' ## Installing: "getsafe.m" (text)') fout = fopen('getsafe.m', 'w'); %function [theResult, theSuccess] = getsafe(theHandle, theProperty) % %% getsafe -- Fault-tolerant "get". %% [theValue, theSuccess] = getsafe(theHandle, 'theProperty') %% returns or displays 'theProperty' of theHandle. On error, %% the result is the empty-matrix []. The "success" flag %% is logically true if successful; otherwise, it is false. % %% Copyright (C) 2000 Dr. Charles R. Denham, ZYDECO. %% All Rights Reserved. %% Disclosure without explicit written consent from the %% copyright owner does not constitute publication. % %% Version of 20-Apr-2000 15:09:26. %% Updated 20-Apr-2000 15:37:07. % %if nargin < 1 % help(mfilename) % theHandle = 'demo'; % return %end % %if isequal(theHandle, 'demo') % c{1} = 'getsafe(0, ''FooBar'')'; % c{2} = 'getsafe(0, ''Language'')'; % for i = 1:length(c) % [result, status] = eval(c{i}); % if ischar(result) % result = ['''' result '''']; % else % result = mat2str(result) % end % disp([' ## ' c{i} ' ==> ' mat2str(result) '; status = ' int2str(status)]) % end % return %end % %result = []; %theSuccess = 0; % %if nargin > 1 % try % result = get(theHandle, theProperty); % theSuccess = 1; % catch % end %end % %if nargout > 0 % theResult = result; %elseif isempty(result) % disp(' []') %else % disp(result) %end fclose(fout); disp(' ## Installing: "gridterp.m" (text)') fout = fopen('gridterp.m', 'w'); %function zi = gridterp(x, y, z, xi, yi) % %% gridterp -- Interpolation of non-plaid grid. %% gridterp('demo') demonstrates itself. %% gridterp(N) demonstrates itself with an N-by-N surface %% and N points along a random track (default = 10). %% gridterp(x, y, z, xi, yi) interpolates the irregular %% z(x, y) rectangular grid at the (xi, yi) positions, %% using TERP4, an internal subroutine. When z is %% three-dimensional, the result bears one row for each %% layer, representing the volumetric slice. (For an %% (x, y) grid that is known to be "plaid", one can use %% INTERP2, which has more options.) % %% Copyright (C) 2000 Dr. Charles R. Denham, ZYDECO. %% All Rights Reserved. %% Disclosure without explicit written consent from the %% copyright owner does not constitute publication. % %% Version of 20-Jan-2000 12:17:03. %% Updated 07-Nov-2001 17:22:09. % %if nargin < 1, x = 'demo'; help(mfilename), end % %if isequal(x, 'demo'), x = 10; end % %if ischar(x), x = eval(x); end % %% Demonstration. % %if length(x) < 2 % n = x; % i = linspace(0, 1, n+1); % [x, y] = meshgrid(i, i); % z = x + y; % xi = sort(rand(1, n)); % yi = rand(size(xi)); % % if (0) % x = x + (rand(size(x)) - 0.5) / n / 2; % y = y + (rand(size(y)) - 0.5) / n / 2; % x = x - min(min(x)); x = x / max(max(x)); % y = y - min(min(y)); y = y / max(max(y)); % end % % tic % result = feval(mfilename, x, y, z, xi, yi); % elapsed = fix(toc*10)/10; % if elapsed > 0 % disp([' ## Elapsed time: ' num2str(elapsed) ' s']) % end % surf(x, y, z); % hold on % plot3(xi, yi, 0*result-1, '-g', 'LineWidth', 3); % plot3(xi, yi, 0*result+3, '-g', 'LineWidth', 3); % plot3([xi;xi], [yi; yi], [0*result-1; 0*result+3], '-ko') % plot3(xi, yi, result+0.01, '-k', 'LineWidth', 3); % hold off % box on % shading faceted % rotate3d off, rotate3d on % figure(gcf) % s = [mfilename ' ' int2str(n)]; % set(gcf, 'Name', s) % return %end % %% Convert rectangular grid to triangles. % %[m, n] = size(x); %k = zeros(m, n); %k(:) = 1:prod(size(k)); %k = k(1:end-1, 1:end-1); % %FASTER = ~~1; % %if FASTER % Genuine Delaunay order. % k = k.'; % k's run across in Delaunay. % k = k(:); % upper = [k k+m+1 k+m]; % lower = [k+1 k+1+m k]; % together = [upper lower].'; % tri = reshape(together, [3, prod(size(together))/3]).'; %else % Homegrown order. % k = k(:); % tri = [k k+1 k+m+1; k k+m+1 k+m]; %end % %% We can compute the upper and lower triangles separately, %% then interleave them. % %quads = tri(:, 1); % %% Find enclosing triangles for (xi, yi). %% Would be nice to use TSEARCH for speed. % %if FASTER % Genuine Delaunay order. % k = tsearch(x(:), y(:), tri, xi(:), yi(:)); %else % Homegrown order. % k = tsearchsafe(x(:), y(:), tri, xi(:), yi(:)); %end % %f = find(isfinite(k)); % In-bounds indices. % %% Identify the corresponding rectangles. % %q = zeros(size(k)) + NaN; %good = isfinite(k); %q(good) = quads(k(good)); % %% Each NaN needs to be checked further, %% since on-the-line is considered out. %% (Should probably use "nearest" mode.) % %if any(isnan(q)) % [m, n] = size(x); % for i = 1:length(q) % ii = []; % if ~isfinite(q(i)) % [ii, jj] = find(xi(i) == x & yi(i) == y); % end % if any(ii) % ii = min(ii(1), m-1); % jj = min(jj(1), n-1); % index = ii + (jj-1)*m; % q(i) = index; % end % end %end % %if ~any(isfinite(q)) % disp([' ## ' mfilename ': result is all NaNs']) % zi = zeros(size(xi)) + NaN; % return %end % %% Interpolate each layer. % %nLayers = size(z, 3); %zi = zeros([nLayers length(xi)]) + NaN; % %for i = 1:nLayers % ztemp = squeeze(z(:, :, i)); % for j = 1:length(q) % if ~isnan(q(j)) % k = q(j); % indices = [k k+1 k+1+m k+m]; % xx = x(indices); % yy = y(indices); % zz = ztemp(indices); % zi(i, j) = terp4(xx, yy, zz, xi(j), yi(j)); % end % end %end % %% Restore orientation. % %if nLayers < 2, zi = reshape(zi, size(xi)); end % % %% ---------- tsearchsafe ---------- % % %function theResult = tsearchsafe(x, y, tri, xi, yi) % %% tsearchsafe -- TSEARCH for arbitrary triangles. %% tsearchsafe('demo') demonstrates itself by %% invoking "tsearch(10)". %% tsearchsafe(NTRI, NPTS) demonstrates itself with %% NTRI triangles and NPTS test-points (defaults: %% NTRI=10, NPTS=10*NTRI). %% tsearchsafe(x, y, tri, xi, yi) mimics TSEARCH for %% an arbitrary group of non-overlapping triangles, %% not necessarily produced by DELAUNAY. The result %% is an array of triangle indices for those points %% that lie on or within at least one triangle. All %% other points are represented by NaN. For points %% lying on or within more than one triangle, only %% one such boundary is identified, as in TSEARCH. %% %% Note: This routine exists because TSEARCH itself %% is not reliable for non-Delaunay sets of triangles. % %% Copyright (C) 2000 Dr. Charles R. Denham, ZYDECO. %% All Rights Reserved. %% Disclosure without explicit written consent from the %% copyright owner does not constitute publication. % %% Version of 04-Apr-2000 15:24:36. %% Updated 07-Apr-2000 14:28:36. % %if nargout > 0, theResult = []; end % %if nargin < 1, x = 'demo'; end % %if isequal(x, 'demo'), help(mfilename), x = 10; end %if ischar(x), x= eval(x); end % %if length(x) == 1 % nTriangles = max(x, 5); % if nargin < 2, y = 10*x; end % if ischar(y), y = eval(y); end % nPoints = max(y, 10); % x = 0.75*rand(2*nTriangles, 1) + 1/8; % y = 0.75*rand(2*nTriangles, 1) + 1/8; % tri = delaunay(x, y); % [r, indices] = sort(rand(size(tri, 1)), 1); % tri = tri(indices(1:nTriangles), :); % xi = rand(nPoints, 1); % yi = rand(nPoints, 1); % tic; % result = feval(mfilename, x, y, tri, xi, yi); % disp([' ## Elapsed time: ' num2str(toc) ' s']) % if nargout > 0 % theResult = result; % else % theDefaultMarkerSize = get(0, 'DefaultLineMarkerSize'); % theDefaultLineWidth = get(0, 'DefaultLineLineWidth'); % theMarkerSize = theDefaultMarkerSize/sqrt(nPoints/1000); % theMarkerSize = min(theDefaultMarkerSize, ... % max(theDefaultLineWidth, theMarkerSize)); % f = find(~isnan(result)); % g = find(isnan(result)); % hold off % h = plot(xi(f), yi(f), 'g+', ... % xi(g), yi(g), 'r+', ... % 'MarkerSize', theMarkerSize); % hold on % trimesh(tri, x, y, zeros(size(x)), ... % 'EdgeColor', [0 0 1], ... % 'FaceColor', 'none', ... % 'LineWidth', 0.5) % hold off % view(2) % grid off % try, zoomsafe, catch, zoom on, end % figure(gcf) % set(gcf, 'Name', [mfilename ' ' int2str(nTriangles) ' ' int2str(nPoints)]) % if nargout > 0, theResult = result; end % end % return %end % %result = zeros(size(xi)) + NaN; % %% Compute bounding rectangles for triangles. % %t = tri.'; %xmin = min(x(tri.')).'; %xmax = max(x(tri.')).'; %ymin = min(y(tri.')).'; %ymax = max(y(tri.')).'; % %% Eliminate out-of-bounds points from %% further consideration. % %g = find(xi >= min(xmin) & xi <= max(xmax) & ... % yi >= min(ymin) & yi <= max(ymax)); % %if (0) % eliminated = length(xi) - length(g) %end % %% For each point, find all the triangles %% for which each point lies within their %% bounding rectangles, then perform TSEARCH %% on each one. We depend on the assumption %% that TSEARCH is reliable for a single %% triangle and many points. % %% NOTE: By pre-sorting the triangles and the (xi, yi) %% points, we could reduce the calculation time, by %% (say) working from right-to-left. %% Also, whereas we presently loop over the (xi, yi), %% we could also do the opposite, depending on the %% relative numbers of triangles and (xi, yi) points. % %for j = 1:length(g) % k = g(j); % xtemp = xi(k); % ytemp = yi(k); % f = find( ... % Points strictly inside the bounds. % (xtemp > xmin) & ... % (xtemp < xmax) & ... % (ytemp > ymin) & ... % (ytemp < ymax)); % if any(f) % for i = 1:length(f) % index = tsearch(x, y, tri(f(i), :), xtemp, ytemp); % if ~isnan(index) % result(k) = f(i); % end % end % end %end % %if nargout > 0 % theResult = result; %else % disp(result) %end % % %% ---------- terp4 ---------- % % %function zi = terp4(x, y, z, xi, yi) % %% terp4 -- Interpolate inside a quadralateral. %% terp('demo') demonstrates itself on a 10-by-10 %% grid. %% terp(N) demonstrates itself on an N-by-N grid, %% where N defaults to 10. %% terp4(x, y, z, xi, yi) interpolates z(x, y) %% at points (xi, yi), using the polynomial %% a*x*y + b*x + c*y + 1 = z, a saddle that %% is equivalent to bilinear interpolation %% on a rectangle. The data here can be %% arbitrary, so long as at least four %% of the (x, y) positions are unique. % %% Copyright (C) 2000 Dr. Charles R. Denham, ZYDECO. %% All Rights Reserved. %% Disclosure without explicit written consent from the %% copyright owner does not constitute publication. % %% Version of 26-Apr-2000 09:14:46. %% Updated 26-Apr-2000 09:14:46. % %if nargin < 1, help(mfilename), x = 'demo'; end % %if isequal(x, 'demo'), x = 10; end %if ischar(x), x = eval(x); end % %if length(x) == 1 % n = x; % x = [0 1 1 0]; % y = [0 0 1 1]; % z = rand(size(x)); % z = z - min(min(z)); z = z ./ max(max(z)); % xi = linspace(0, 1, n); % yi = linspace(0, 1, n); % [xi, yi] = meshgrid(xi, yi); % result = feval(mfilename, x, y, z, xi, yi); % surf(xi, yi, result) % rotate3d off % rotate3d on % return %end % %xmin = min(x(:)); %ymin = min(y(:)); % %x = x - xmin; y = y - ymin; %xi = xi - xmin; yi = yi - ymin; % %a = [x(:).*y(:) x(:) y(:) ones(size(x(:)))]; %b = z(:); % %p = a \ b; % %zi = [xi(:).*yi(:) xi(:) yi(:) ones(size(xi(:)))] * p; % %zi = reshape(zi, size(xi)); fclose(fout); disp(' ## Installing: "guido.m" (text)') fout = fopen('guido.m', 'w'); %function theResult = guido(theStruct, theFigureName, isModal, thePrecision) % %% guido -- Get info via Matlab struct. %% guido('demo') demonstrates itself, using the commands %% given below. %% guido(theStruct, 'theFigureName') presents a dialog %% representing the fieldnames and values of theStruct, %% a Matlab "struct" which must be compatible with %% "getinfo" and "setinfo". If theStruct contains %% embedded structs, nested dialogs are produced for %% them as needed. The empty-matrix [] is returned %% if the main "Cancel" button is pressed. Also, use %% "Cancel" to escape a sub-dialog without saving its %% most recent changes. Fields named "help_..." are %% shown in a separate dialog. If theFigureName is %% not given or is empty, the external name of %% theStruct will be used. %% guido(theStruct, 'theFigureName', isModal) uses modal %% dialogs on non-PCWIN machines if "isModal" evaluates %% to logical(1) TRUE. The default is to use non-modal %% dialogs, which allows interactions with other windows, %% except the Matlab command window. In either case, the %% the routine prevents dialogs from being dismissed out %% of sequence. %% guido(theStruct, 'theFigureName', isModal, thePrecision) %% uses thePrecision (default = 4) when displaying numbers %% in an "edit" control. %% %% Commands used in the demonstration: %% %% s.help = help(mfilename); %% s.anEdit = 'some text'; %% s.aNumber = pi; %% s.aCheckbox = {'checkbox' 0}; %% s.aRadiobutton = {'radiobutton' 0}; %% s.aPopupmenu = {{'red', 'blue', 'green'}, 1}; %% s.aSubdialog.aPopupmenu = {{10 20 30}, 1}; %% guido(s, [mfilename ' demo']) % %% Note: the present m-file can be renamed without %% requiring any changes to the Matlab code itself. % %% Copyright (C) 1999 Dr. Charles R. Denham, ZYDECO. %% All Rights Reserved. %% Disclosure without explicit written consent from the %% copyright owner does not constitute publication. % %% Version of 15-Dec-1999 13:39:54. %% Updated 25-Jan-2000 11:47:42. % %persistent CURRENT_STRUCT %persistent CURRENT_FIGURES % %LF = char(10); %CR = char(13); %CRLF = [CR LF]; %BABY_BLUE = [8 10 10]/10; % %if nargout > 0, theResult = []; end % %% Launch a demo if this is not a callback. % %if nargin < 1 & isempty(gcbo) % help(mfilename) % ans = feval(mfilename, 'demo'); % if nargout > 0 % theResult = CURRENT_STRUCT; % else % assignin('caller', 'ans', CURRENT_STRUCT) % end % return %end % %% Do the demo. % %if nargin > 0 & isequal(theStruct, 'demo') % if nargin < 2, theFigureName = [mfilename ' demo']; end % s = []; % s.help = help(mfilename); % s.anEdit = 'some text'; % s.aNumber = pi; % s.aCheckbox = {'checkbox' 0}; % s.aRadiobutton = {'radiobutton' 0}; % s.aPopupmenu = {{'red', 'blue', 'green'}, 1}; % s.aSubdialog.aPopupmenu = {{10 20 30}, 1}; %% s.aSubdialog.bSubdialog.bPopupmenu = {{100 200 300}, 1}; % disp(s) % % assign([mfilename '_demo'], s) % result = feval(mfilename, eval([mfilename '_demo']), '', 0); % assign([mfilename '_result'], result) % % if ~isempty(eval([mfilename '_result'])) % result = feval(mfilename, eval([mfilename '_result']), '', 0); % assign([mfilename '_result'], result) % end % if nargout > 0 % assign('theResult', [mfilename '_result']) % end % return %end % %if nargin > 0 & ischar(theStruct) % theCommand = lower(theStruct); %end % %if 0 & nargin > 0 & ischar(theStruct) % switch theCommand % case '_keypress_' % theKey = get(gcbf, 'CurrentCharacter'); % if any(abs(theKey) < 32) % theCommand = '_okay_'; % end % end %end % %% Dismiss dialogs in sequence. % %if nargin > 0 & ischar(theStruct) % switch theCommand % case {'_okay_', '_cancel_'} % CURRENT_FIGURES(~ishandle(CURRENT_FIGURES)) = []; % if ~isempty(CURRENT_FIGURES) & gcbf ~= CURRENT_FIGURES(end) % figure(CURRENT_FIGURES(end)) % h = helpdlg('Dismiss dialogs in sequence.', 'Please...'); % tic % while ishandle(h) & toc < 3 % drawnow % end % if ishandle(h), delete(h), end % return % end % end %end % %% Process a command: okay or cancel. % %if nargin > 0 & ischar(theStruct) % switch theCommand % case '_okay_' % CURRENT_STRUCT = get(gcbf, 'UserData'); % theControls = findobj(gcbf, 'Type', 'uicontrol', 'Tag', mfilename); % theControls = sort(theControls); % for i = 2:2:length(theControls) % theField = get(theControls(i-1), 'String'); % theControl = theControls(i); % theStyle = get(theControl, 'Style'); % switch theStyle % case 'pushbutton' % okay = 0; % case 'checkbox' % theValue = get(theControl, 'Value'); % okay = 1; % case 'radiobutton' % theValue = get(theControl, 'Value'); % okay = 1; % case 'edit' % if isequal(theField, 'help') % okay = 0; % else % theValue = eval(get(theControl, 'String')); % okay = 1; % end % case 'popupmenu' % theValue = get(theControl, 'Value'); % okay = 1; % otherwise % okay = 0; % warning([' ## Unsupported control style: ' theStyle]) % end % if okay % CURRENT_STRUCT = setinfo(CURRENT_STRUCT, theField, theValue); % end % end % if ~isempty(CURRENT_FIGURES) & any(CURRENT_FIGURES == gcbf) % CURRENT_FIGURES(CURRENT_FIGURES == gcbf) = []; % end % delete(gcbf) % case '_cancel_' % CURRENT_STRUCT = []; % if ~isempty(CURRENT_FIGURES) & any(CURRENT_FIGURES == gcbf) % CURRENT_FIGURES(CURRENT_FIGURES == gcbf) = []; % end % delete(gcbf) % otherwise % disp([' ## Unknown command: ' theCommand]) % end % return %end % %% Build the dialog if it does not already exist. % %if nargin > 0 & isstruct(theStruct) % theStruct = setinfo(theStruct); % if nargin < 2 | isempty(theFigureName) % theFigureName = inputname(1); % if isempty(theFigureName) % theFigureName = 'unnamed'; % end % end % if isempty(theFigureName), theFigureName = mfilename; end % % f = findobj('Type', 'figure', 'Name', theFigureName, 'Tag', mfilename); % if any(f) % figure(f) % return % end % % if nargin < 3, isModal = 0; end % if nargin < 4, thePrecision = 4; end % % if all(isModal(:)) & ~any(findstr(computer, 'PCWIN')) % theWindowStyle = 'modal'; % else % theWindowStyle = 'normal'; % end % theFigures = findobj('Type', 'figure', 'Tag', mfilename); % theFigure = figure( ... % 'Name', theFigureName, ... % 'WindowStyle', theWindowStyle, ... % 'Visible', 'off', ... % 'KeyPressFcn', [mfilename ' _keypress_'], ... % 'CloseRequestFcn', [mfilename ' _cancel_'], ... % 'Tag', mfilename); % if any(theFigures) % pos = get(theFigures(1), 'Position'); % left = pos(1); % top = pos(2) + pos(4); % for i = 2:length(theFigures) % p = get(theFigures(i), 'Position'); % left = max(pos(1), p(1)); % top = min(top, p(2) + p(4)); % end % thePosition = get(theFigure, 'Position'); % thePosition(1) = left + 20; % thePosition(2) = top - thePosition(4) - 20; % set(theFigure, 'Position', thePosition) % end % theFrame = uicontrol( ... % 'Style', 'frame', ... % 'Units', 'normalized', ... % 'Position', [0 0 1 1], ... % 'BackgroundColor', BABY_BLUE); % theControls = []; % theStruct = setinfo(theStruct); % Canonical form. % theFields = fieldnames(theStruct); % for i = 1:length(theFields) % theField = theFields{i}; % theValue = getfield(theStruct, theField); % switch class(theValue) % case 'cell' % switch class(theValue{1}) % case 'cell' % if length(theValue) > 1 % theSetting = theValue{2}; % else % theSetting = 1; % theValue = {theValue, theSetting}; % theStruct = setfield(theStruct, theField, theValue); % end % theStyle = 'popupmenu'; % case 'char' % switch theValue{1} % case 'checkbox' % theStyle = 'checkbox'; % if length(theValue) > 1 % theSetting = theValue{2}; % else % theSetting = 0; % end % case 'radiobutton' % theStyle = 'radiobutton'; % if length(theValue) > 1 % theSetting = theValue{2}; % else % theSetting = 0; % end % otherwise % error([' ## Incompatible control style: ' theValue{1}]) % end % end % theControls(end+1) = uicontrol( ... % 'Style', 'text', ... % 'String', theField); % theControls(end+1) = uicontrol( ... % 'Style', theStyle, ... % 'String', theValue{1}, ... % 'Value', theSetting); % case 'char' % f = findstr(theField, 'help_'); % if ~any(f) | f(1) ~= 1 % theControls(end+1) = uicontrol( ... % 'Style', 'text', ... % 'String', theField); % theControls(end+1) = uicontrol( ... % 'Style', 'edit', ... % 'Max', 1000, ... % 'String', ['''' theValue '''']); % else % theHintName = [theField ' ' theFigureName]; % theCallback = ... % ['hint(get(gcbo, ''UserData''), ''' theHintName ''')']; % theControls(end+1) = uicontrol( ... % 'Style', 'text', ... % 'String', theField); % theControls(end+1) = uicontrol( ... % 'Style', 'pushbutton', ... % 'Callback', theCallback, ... % 'UserData', theValue, ... % 'String', 'Help...'); % end % case 'double' % theControls(end+1) = uicontrol( ... % 'Style', 'text', ... % 'String', theField); % theControls(end+1) = uicontrol( ... % 'Style', 'edit', ... % 'Max', 1000, ... % 'String', mat2str(theValue, thePrecision)); % case 'struct' % theCallback = ... % [mfilename '(get(gcbo, ''UserData''), ''' theField ''')']; % theControls(end+1) = uicontrol( ... % 'Style', 'text', ... % 'String', theField); % theControls(end+1) = uicontrol( ... % 'Style', 'pushbutton', ... % 'String', 'More...', ... % 'Callback', theCallback, ... % 'UserData', theValue); % otherwise % disp(class(theValue)) % error([' ## Incompatible data type. ' class(theValue)]) % end % end % set(theControls(1:2:end), ... % 'HorizontalAlignment', 'right', ... % 'BackgroundColor', BABY_BLUE) % theControls(end+1) = uicontrol( ... % 'Style', 'pushbutton', ... % 'String', 'Cancel', ... % 'BackgroundColor', [10 2 2]/10, ... % 'Callback', [mfilename ' _cancel_']); % theControls(end+1) = uicontrol( ... % 'Style', 'pushbutton', ... % 'String', 'Okay', ... % 'BackgroundColor', [2 10 2]/10, ... % 'Callback', [mfilename ' _okay_']); % set(theControls, 'Tag', mfilename) % theLayout = []; % for i = 1:length(theControls)/2 % theLayout = [(1:2:length(theControls)); % (2:2:length(theControls))].'; % end % theLayout = theLayout(:, [1 2 2]); % uilayout(theControls, theLayout, [1 1 18 18]/20) % pos = get(0, 'DefaultUIControlPosition'); % width = pos(3) * 6; % height = 0.5 * length(theControls) * pos(4) * 20 / 15; % thePosition = get(theFigure, 'Position'); % thePosition(2) = thePosition(2) + thePosition(4) - height; % thePosition(3) = width; % thePosition(4) = height; % set(theFigure, 'Position', thePosition, 'Visible', 'on', ... % 'UserData', theStruct) % if any(CURRENT_FIGURES) % CURRENT_FIGURES(~ishandle(CURRENT_FIGURES)) = []; % end % CURRENT_FIGURES(end+1) = theFigure; % %% Wait here for the new figure to be deleted. By then, it will %% already have placed its contents in the persistent CURRENT_STRUCT %% item. % % waitfor(theFigure) % %% Now get the new info from CURRENT_STRUCT and update. % % theNewStruct = CURRENT_STRUCT; % % theFieldName = theFigureName; % % if length(theFigures) < 1 % theStruct = theNewStruct; % else % theFigure = gcf; % theStruct = get(theFigure, 'UserData'); % if ~isfield(theStruct, theFieldName) & ~isequal(theField, 'help') % disp([' ## No such field: ' theField]) % elseif ~isempty(theNewStruct) % theStruct = setfield(theStruct, theFieldName, theNewStruct); % set(theFigure, 'UserData', theStruct) % f = findobj(theFigure, 'Type', 'uicontrol', 'Tag', mfilename); % f = sort(f); % for i = 2:2:length(f) % theField = get(f(i-1), 'String'); % if isequal(theField, theFieldName) % set(f(i), 'UserData', theNewStruct) % break % end % end % end % end % % if nargout > 0 % theResult = theStruct; % else % assignin('caller', 'ans', theStruct); % end % %end % %% ---------- assign ----------% % %function assign(theName, theValue) % %% assign -- Assign a value to a name. %% assign('theName', theValue) assigns theValue %% to 'theName' in the caller's workspace. It %% avoids the need to construct an explicit %% assignment statement to be eval-ed. % %% Copyright (C) 1997 Dr. Charles R. Denham, ZYDECO. %% All Rights Reserved. %% Disclosure without explicit written consent from the %% copyright owner does not constitute publication. % %% Version of 28-May-1998 00:43:58. % %if nargin < 2, help(mfilename), return, end % %% The following scheme permits the assignment %% of items that have complicated subscripts, %% such as "a{1}(2).b{3}.c = pi". % %hasAns = (evalin('caller', 'exist(''ans'', ''var'')') == 1); %if hasAns % ans = evalin('caller', 'ans'); % Save. %end %assignin('caller', 'ans', theValue) %evalin('caller', [theName ' = ans;']) %evalin('caller', 'clear(''ans'')') %if hasAns % assignin('caller', 'ans', ans) % Restore. %end % %% ---------- getinfo ----------% % %function [theResult, isOkay] = getinfo(theInfo, theField) % %% getinfo -- Get field value from an "Info" struct. %% getinfo(theInfo, 'theField') returns the current %% value of 'theField' in theInfo, a struct that %% is compatible with the "uigetinfo" function. %% Non-existent fields return the empty-matrix. %% [theResult, isOkay] = ... returns isOkay = 0 %% if an error occurred; otherwise, non-zero. %% getinfo(theInfo) returns a struct containing %% the fields and current selections of theInfo. % %% Copyright (C) 1997 Dr. Charles R. Denham, ZYDECO. %% All Rights Reserved. %% Disclosure without explicit written consent from the %% copyright owner does not constitute publication. % %% Version of 07-Feb-1998 09:45:56. %% Updated 14-Nov-2001 15:07:51. % %if nargout > 0, theResult = []; end %if nargin < 1, help(mfilename), return, end % %% Get current selections, recursively if needed. % %if nargin < 2 % result = theInfo; % theFields = fieldnames(result); % isOkay = 1; % for i = 1:length(theFields) % [theValue, okay] = getinfo(theInfo, theFields{i}); % isOkay = isOkay & okay; % switch class(theValue) % case 'struct' % [res, okay] = getinfo(theValue); % isOkay = isOkay & okay; % result = setfield(result, theFields{i}, res); % otherwise % result = setfield(result, theFields{i}, theValue); % end % end % if nargout > 0 % theResult = result; % else % disp(result) % end % return %end % %% Note: Matlab 6+ does not allow "getfield(a, 'b.c')", %% unlike previous versions. We need to parse the %% 'b.c' ourselves, then call "getfield(a, 'b', 'c')". % %if ischar(theField) & any(theField == '.') % theField = [theField '.']; % f = find(theField == '.'); % theParts = cell(1, length(f)); % k = 0; % for i = 1:length(f) % theParts{i} = theField(k+1:f(i)-1); % k = f(i); % end % theField = theParts; %elseif ~iscell(theField) % theField = {theField}; %end % %theValue = []; % %isOkay = 1; %% eval('theValue = getfield(theInfo, theField);', 'isOkay = 0;'); %eval('theValue = getfield(theInfo, theField{:});', 'isOkay = 0;'); % %result = theValue; % %if all(isOkay) % switch class(theValue) % case 'cell' % if isequal(theValue{1}, 'checkbox') | ... % isequal(theValue{1}, 'radiobutton') % if length(theValue) < 2, theValue{2} = 0; end % result = theValue{2}; % else % if ~iscell(theValue{1}), theValue = {theValue{1}}; end % if length(theValue) < 2, theValue{2} = 1; end % result = theValue{1}{theValue{2}}; % end % otherwise % result = theValue; % end %end % %if nargout > 0 % theResult = result; %else % disp(result) %end % %% ---------- setinfo ----------% % %function [theResult, isOkay] = setinfo(theInfo, theField, theValue) % %% setinfo -- Set field value in an "Info" struct. %% setinfo(theInfo, 'theField', theValue) updates %% 'theField' to theValue in theInfo, a struct %% that is compatible with the "uigetinfo" function. %% If 'theField' does not exist, it will be created %% to receive theValue. %% [theResult, isOkay] = ... returns isOkay = 0 %% if an error occurred; otherwise, non-zero. %% setinfo(theInfo, 'theField') invokes "getinfo". %% setinfo(theInfo) adjusts theInfo to canonical %% form. % %% Copyright (C) 1997 Dr. Charles R. Denham, ZYDECO. %% All Rights Reserved. %% Disclosure without explicit written consent from the %% copyright owner does not constitute publication. % %% Version of 07-Feb-1998 09:45:56. %% Updated 14-Nov-2001 15:21:24. % %if nargout > 0, theResult = []; end %if nargin < 1, help(mfilename), return, end % %% Put all fields into canonical form. % %if nargin < 2 % result = theInfo; % theFields = fieldnames(result); % isOkay = 1; % for i = 1:length(theFields) % theValue = getfield(result, theFields{i}); % switch class(theValue) % case 'struct' % [res, okay] = setinfo(theValue); % isOkay = isOkay & okay; % result = setfield(result, theFields{i}, res); % case 'cell' % if length(theValue) == 1 & ... % (isequal(theValue{1}, 'radiobutton') | ... % isequal(theValue{1}, 'checkbox')) % theValue{2} = 0; % result = setfield(result, theFields{i}, theValue); % elseif length(theValue) == 1 & iscell(theValue{1}) % theValue{2} = 1; % result = setfield(result, theFields{i}, theValue); % elseif ~isequal(theValue{1}, 'radiobutton') & ... % ~isequal(theValue{1}, 'checkbox') % theValue{1} = {theValue{1}}; % theValue{2} = 1; % else % theValue; % end % otherwise % end % end % if nargout > 0, theResult = result; end % return %end % %[theVal, isOkay] = getinfo(theInfo, theField); % %if nargin == 2 % if nargout > 0 % theResult = theVal; % else % disp(theVal) % end % return %end % %if ischar(theField) & any(theField == '.') % theField = [theField '.']; % f = find(theField == '.'); % theParts = cell(1, length(f)); % k = 0; % for i = 1:length(f) % theParts{i} = theField(k+1:f(i)-1); % k = f(i); % end % theField = theParts; %elseif ~iscell(theField) % theField = {theField}; %end % %result = theInfo; % %if ~all(isOkay) % Create a new field. % isOkay = 1; %% eval('result = setfield(theInfo, theField, theValue);', 'isOkay = 0;'); % eval('result = setfield(theInfo, theField{:}, theValue);', 'isOkay = 0;'); %else % Update an existing field. % isokay = 1; %% eval('theVal = getfield(theInfo, theField);', 'isOkay = 0;'); % eval('theVal = getfield(theInfo, theField{:});', 'isOkay = 0;'); % if ~isOkay, theVal = []; end % switch class(theVal) % case 'cell' % if isequal(theVal{1}, 'checkbox') | isequal(theVal{1}, 'radiobutton') % % Do nothing. % elseif ~iscell(theVal{1}) % theVal{1} = {theVal{1}}; % theVal{2} = 1; % end % end % switch class(theVal) % case 'cell' % if isequal(theVal{1}, 'checkbox') | isequal(theVal{1}, 'radiobutton') % theVal{2} = any(any(theValue)); % else % switch class(theValue) % case 'double' % if theValue > 0 & theValue <= length(theVal{1}) % theVal{2} = theValue; % end % otherwise % flag = 0; % for i = 1:length(theVal{1}) % if isequal(theVal{1}{i}, theValue) % theVal{2} = i; % flag = 1 % end % end % if ~any(flag) % Append. % theVal{1} = [theVal(:); {theValue}]; % theVal{2} = length(theVal{1}); % end % end %% else %% theVal{1} = [{theValue}; theVal(:)]; % end % otherwise % theVal = theValue; % end % isOkay = 1; %% eval('result = setfield(theInfo, theField, theVal);', 'isOkay = 0;'); % eval('result = setfield(theInfo, theField{:}, theVal);', 'isOkay = 0;'); %end % %if nargout > 0 % theResult = result; %else % disp(result) %end % %% ---------- uilayout ----------% % %function theResult = uilayout(theControls, theLayout, thePosition) % %% uilayout -- Layout for ui controls. %% uilayout(theControls, theLayout) positions theControls %% according to theLayout, an array whose entries, taken %% in sorted order, define the rectangular extents occupied %% by each control. TheLayout defaults to a simple vertical %% arrangement of theControls. A one-percent margin is %% imposed between controls. To define a layout region %% containing no control, use Inf. %% uilayout(..., thePosition) confines the controls to the %% given normalized position of the figure. This syntax %% is useful for embedding controls within a frame. %% uilayout (no argument) demonstrates itself. % %% Copyright (C) 1997 Dr. Charles R. Denham, ZYDECO. %% All Rights Reserved. %% Disclosure without explicit written consent from the %% copyright owner does not constitute publication. % %% Version of 18-Apr-1997 08:07:54. %% Updated 27-Dec-1999 06:03:57. % %if nargin < 1, theControls = 'demo'; help(mfilename), end % %if strcmp(theControls, 'demo') % theLayout = [1 2; % 3 4; % 5 Inf; % 5 6; % 5 Inf; % 7 8; % 9 10; % 11 12; % 13 14]; % [m, n] = size(theLayout); % thePos = get(0, 'DefaultUIControlPosition'); % theSize = [n+2 m+2] .* thePos(3:4); % theFigure = figure('Name', 'UILayout', ... % 'NumberTitle', 'off', ... % 'Resize', 'off', ... % 'Units', 'pixels'); % thePos = get(theFigure, 'Position'); % theTop = thePos(2) + thePos(4); % thePos = thePos .* [1 1 0 0] + [0 0 theSize]; % thePos(2) = theTop - (thePos(2) + thePos(4)); % set(theFigure, 'Position', thePos); % theFrame = uicontrol('Style', 'frame', ... % 'Units', 'normalized', ... % 'Position', [0 0 1 1], ... % 'BackgroundColor', [0.5 1 1]); % theStyles = {'checkbox'; 'text'; ... % 'edit'; 'text'; ... % 'listbox'; 'text'; ... % 'popupmenu'; 'text'; ... % 'pushbutton'; 'text'; ... % 'radiobutton'; 'text'; ... % 'text'; 'text'}; % theStrings = {'Anchovies?', '<-- CheckBox --', ... % 'Hello World!', '<-- Edit --', ... % {'Now', 'Is', 'The' 'Time' 'For' 'All' 'Good', ... % 'Men', 'To', 'Come' 'To' 'The' 'Aid' 'Of', ... % 'Their' 'Country'}, ... % '<-- ListBox --', ... % {'Cheetah', 'Leopard', 'Lion', 'Tiger', 'Wildcat'}, ... % '<-- PopupMenu --', ... % 'Okay', '<-- PushButton --', ... % 'Cream?', '<-- RadioButton --', ... % 'UILayout', '<-- Text --'}; % theControls = zeros(size(theStyles)); % for i = 1:length(theStyles) % theControls(i) = uicontrol('Style', theStyles{i}, ... % 'String', theStrings{i}, ... % 'Callback', ... % 'disp(int2str(get(gcbo, ''Value'')))'); % end % set(theControls(1:2:length(theControls)), 'BackGroundColor', [1 1 0.5]) % set(theControls(2:2:length(theControls)), 'BackGroundColor', [0.5 1 1]) % thePosition = [1 1 98 98] ./ 100; % uilayout(theControls, theLayout, thePosition) % set(theFrame, 'UserData', theControls) % theStyles, theLayout, thePosition % if nargout > 0, theResult = theFrame; end % return %end % %if nargin < 2, theLayout = (1:length(theControls)).'; end %if nargin < 3, thePosition = [0 0 1 1]; end % %a = theLayout(:); %a = a(finite(a)); %a = sort(a); %a(diff(a) == 0) = []; % %b = zeros(size(theLayout)); % %for k = 1:length(a) % b(theLayout == a(k)) = k; %end % %[m, n] = size(theLayout); % %set(theControls, 'Units', 'Normalized') %theMargin = [1 1 -2 -2] ./ 100; %for k = 1:min(length(theControls), length(a)) % [i, j] = find(b == k); % xmin = (min(j) - 1) ./ n; % xmax = max(j) ./ n; % ymin = 1 - max(i) ./ m; % ymax = 1 - (min(i) - 1) ./ m; % thePos = [xmin ymin (xmax-xmin) (ymax-ymin)] + theMargin; % thePos = thePos .* thePosition([3 4 3 4]); % thePos(1:2) = thePos(1:2) + thePosition(1:2); % set(theControls(k), 'Position', thePos); %end % %if nargout > 0, theResult = theControls; end % %% ---------- hint ----------% % %function theResult = hint(theText, theFigureName) % %% hint -- Post a message. %% hint('theText', 'theFigureName') posts 'theText' in the %% figure named 'theFigureName', which will be created if %% it does not already exist. The text can be a string %% separated by newlines, or a cell of strings. %% hint('demo') demonstrates itself. % %% Copyright (C) 1999 Dr. Charles R. Denham, ZYDECO. %% All Rights Reserved. %% Disclosure without explicit written consent from the %% copyright owner does not constitute publication. % %% Version of 17-Dec-1999 11:31:03. %% Updated 04-Jan-2000 13:40:41. % %if nargin < 1, theText = 'demo'; end % %if isequal(theText, 'demo') % hint(help(mfilename), 'Hint Hint') % return %end % %CR = char(13); %LF = char(10); %CRLF = [CR LF]; % %if nargout > 0, theResult = []; end %if nargin < 1 % help(mfilename) % theText = help(mfilename); % for i = 1:3 % theText = [theText theText]; % end %end %if nargin < 2, theFigureName = 'Help'; end % %if min(size(theText)) == 1 % theText = theText(:).'; %end % %if ischar(theText) & size(theText, 1) == 1 % theText = strrep(theText, CRLF, CR); % theText = strrep(theText, LF, CR); % if theText(end) ~= CR, theText(end+1) = CR; end % if theText(1) ~= CR, theText = [CR theText]; end % f = find(theText == CR); % if any(f) % s = cell(length(f)-1, 1); % for i = 1:length(f)-1 % if f(i)+1 < f(i+1)-1 % s{i} = theText(f(i)+1:f(i+1)-1); % else % s{i} = ' '; % end % end % theText = s; % end %end % %theLineCount = size(theText, 1); % %theFigure = findobj( ... % 'Type', 'figure', ... % 'Name', theFigureName, ... % 'Tag', [mfilename ' hint'] ... % ); %if isempty(theFigure) % theFigures = findobj('Type', 'figure'); % if any(theFigures) % thePosition = get(gcf, 'Position'); % left = thePosition(1); % top = thePosition(2) + thePosition(4); % end % theFigure = figure( ... % 'Name', theFigureName, ... % 'Tag', mfilename, ... % 'Visible', 'off' ... % ); % if any(theFigures) % set(theFigure, 'Position', thePosition + [20 -20 0 0]) % end %end % %delete(get(theFigure, 'Children')) % %theColor = [9 9 9]/10; %theFontName = 'Courier'; %if any(findstr(lower(computer), 'mac')) % theFontName = 'Monaco'; %end %theFontSize = 12; %theListBox = uicontrol( ... % theFigure, ... % 'Style', 'listbox', ... % 'String', theText, ... % 'FontName', theFontName, ... % 'FontSize', theFontSize, ... % 'HorizontalAlignment', 'left', ... % 'BackgroundColor', theColor ... % ); % %uilayout(theListBox, 1) % %set(theFigure, 'Visible', 'on') %figure(theFigure) % %if nargout > 0 % theResult = theFigure; %end fclose(fout); disp(' ## Installing: "hello.m" (text)') fout = fopen('hello.m', 'w'); %function theResult = hello(varargin) % %% hello -- Display a message. %% hello(theMessage) displays 'hello' plus theMessage. %% If called from a subroutine, the line-number and %% function-name are included in the display. % %% Copyright (C) 1996 Dr. Charles R. Denham, ZYDECO. %% All Rights Reserved. %% Disclosure without written consent from the %% copyright owner does not constitute publication. % %% Updated 03-May-2001 19:11:40. % %if nargin < 1, theMessage = ''; end % %[stack, index] = dbstack; % %if length(stack) > 1 % stack = stack(2); %else % stack = []; % stack.line = 0; % stack.name = ''; %end % %if ~isempty(stack.name) % s = [' ## hello at "' stack.name '" line ' int2str(stack.line)]; %else % s = [' ## hello']; %end % %for i = 1:length(varargin) % s = [s ' ' mat2str(varargin{i})]; %end % %if nargout < 1 % disp(s) %else % theResult = s; %end fclose(fout); disp(' ## Installing: "hint.m" (text)') fout = fopen('hint.m', 'w'); %function theResult = hint(theText, theFigureName) % %% hint -- Post a message. %% hint('theText', 'theFigureName') posts 'theText' in the %% figure named 'theFigureName', which will be created if %% it does not already exist. The text can be a string %% separated by newlines, or a cell of strings. %% hint('demo') demonstrates itself. % %% Copyright (C) 1999 Dr. Charles R. Denham, ZYDECO. %% All Rights Reserved. %% Disclosure without explicit written consent from the %% copyright owner does not constitute publication. % %% Version of 17-Dec-1999 11:31:03. %% Updated 04-Jan-2000 13:40:41. % %if nargin < 1, theText = 'demo'; end % %if isequal(theText, 'demo') % hint(help(mfilename), 'Hint Hint') % return %end % %CR = char(13); %LF = char(10); %CRLF = [CR LF]; % %if nargout > 0, theResult = []; end %if nargin < 1 % help(mfilename) % theText = help(mfilename); % for i = 1:3 % theText = [theText theText]; % end %end %if nargin < 2, theFigureName = 'Help'; end % %if min(size(theText)) == 1 % theText = theText(:).'; %end % %if ischar(theText) & size(theText, 1) == 1 % theText = strrep(theText, CRLF, CR); % theText = strrep(theText, LF, CR); % if theText(end) ~= CR, theText(end+1) = CR; end % if theText(1) ~= CR, theText = [CR theText]; end % f = find(theText == CR); % if any(f) % s = cell(length(f)-1, 1); % for i = 1:length(f)-1 % if f(i)+1 < f(i+1)-1 % s{i} = theText(f(i)+1:f(i+1)-1); % else % s{i} = ' '; % end % end % theText = s; % end %end % %theLineCount = size(theText, 1); % %theFigure = findobj( ... % 'Type', 'figure', ... % 'Name', theFigureName, ... % 'Tag', mfilename ... % ); %if isempty(theFigure) % theFigures = findobj('Type', 'figure'); % if any(theFigures) % thePosition = get(gcf, 'Position'); % left = thePosition(1); % top = thePosition(2) + thePosition(4); % end % theFigure = figure( ... % 'Name', theFigureName, ... % 'Tag', mfilename, ... % 'Visible', 'off' ... % ); % if any(theFigures) % set(theFigure, 'Position', thePosition + [20 -20 0 0]) % end %end % %delete(get(theFigure, 'Children')) % %theColor = [9 9 9]/10; %theFontName = 'Courier'; %if any(findstr(lower(computer), 'mac')) % theFontName = 'Monaco'; %end %theFontSize = 12; %theListBox = uicontrol( ... % theFigure, ... % 'Style', 'listbox', ... % 'String', theText, ... % 'FontName', theFontName, ... % 'FontSize', theFontSize, ... % 'HorizontalAlignment', 'left', ... % 'BackgroundColor', theColor ... % ); % %uilayout(theListBox, 1) % %set(theFigure, 'Visible', 'on') %figure(theFigure) % %if nargout > 0 % theResult = theFigure; %end fclose(fout); disp(' ## Installing: "identical.m" (text)') fout = fopen('identical.m', 'w'); %function theResult = identical(varargin) % %% identical -- Nan-safe "isequal". %% identical(x, y, ...) returns TRUE if all the %% arguments are identical in shape and value, %% even with respect to NaNs. No distinction %% is made between the number-like classes. % %% Copyright (C) 2001 Dr. Charles R. Denham, ZYDECO. %% All Rights Reserved. %% Disclosure without explicit written consent from the %% copyright owner does not constitute publication. % %% Version of 05-Sep-2001 01:48:57. %% Updated 05-Sep-2001 02:32:14. % %if nargout > 0, theResult = []; end %if nargin < 2, help(mfilename), return, end % %% Check "isequal" first. % %yes = isequal(varargin{:}); %if yes % if nargout > 0 % theResult = yes; % else % disp(yes) % end % return %end % %% Not exactly equal. Decompose the arguments, %% checking for equality of the pieces. % %x = varargin{1}; % %for k = 2:length(varargin) % y = varargin{k}; % yes = isequal(x, y); % if ~yes % switch class(x) % case 'cell' % if isequal(class(y), 'cell') % if isequal(size(x), size(y)) % for i = 1:prod(size(x)) % yes = feval(mfilename, x{i}, y{i}); % if ~yes, break, end % end % end % end % case 'struct' % if isequal(class(y), 'struct') % fx = fieldnames(x); % if isequal(fx, fieldnames(y)) % for i = 1:length(fx) % gx = getfield(x, fx{i}); % gy = getfield(y, fx{i}); % yes = feval(mfilename, gx, gy); % if yes, break, end % end % end % end % case {'char', 'double', 'sparse', 'uint8', 'uint32'} % nx = isnan(x); % if isequal(size(x), size(y)) & any(nx(:)) % ny = isnan(y); % if isequal(nx, ny) % yes = isequal(x(~nx), y(~ny)); % end % end % otherwise % end % end % if ~yes, break, end %end % %if nargout > 0 % theResult = yes; %else % disp(yes) %end fclose(fout); disp(' ## Installing: "idle.m" (text)') fout = fopen('idle.m', 'w'); %function Idle(theFigure) % %% Idle -- Set the arrow-cursor. %% Idle(theFigure) sets the arrow-cursor in theFigure. %% The companion routine is "Busy". % %% Copyright (C) 1996 Dr. Charles R. Denham, ZYDECO. %% All Rights Reserved. % %if ~any(findobj('Type', 'figure')), return, end % %if nargin < 1, theFigure = gcf; end % %set(theFigure, 'Pointer', 'arrow'); fclose(fout); disp(' ## Installing: "inherit.m" (text)') fout = fopen('inherit.m', 'w'); %function sys = inherit(sys,pre) %%INHERIT Lets a new IDMODEL object inherit the properties of another one. %% Except ParameterVector, CovarianceMatrix and NoiseVariance. %% %% SYS = INHERIT(SYS,OLDSYS) % %% Copyright 1986-2001 The MathWorks, Inc. %% $Revision: 1.11 $ $Date: 2001/12/14 11:41:06 $ % % %%% Inherit everything but parameter vector and covariancematrix %idm = pvget(pre,'idmodel'); %par = pvget(sys,'ParameterVector'); %cov = pvget(sys,'CovarianceMatrix'); %noisev = pvget(sys,'NoiseVariance'); %%noi = pvget(sys,'NoiseVariance'); %idm = pvset(idm,'ParameterVector',par,'CovarianceMatrix',cov,... % 'NoiseVariance',noisev); %sys = pvset(sys,'idmodel',idm); fclose(fout); disp(' ## Installing: "insidesafe.m" (text)') fout = fopen('insidesafe.m', 'w'); %function theResult = insidesafe(x, y, px, py, theChunkSize, theVerboseFlag) % %% insidesafe -- Points in polygon via "inpolygon". %% insidesafe('demo') demonstrates itself with 100 random points. %% insidesafe(N) demonstrates itself with N random points (default = 100). %% insidesafe(x, y, px, py) calls "inpolygon" to determine %% which (x, y) points are inside the polygon with vertices %% (px, py). Result is 1 for inside, 0 for outside, and 0.5 %% for on-the-line. %% insidesafe(..., theChunkSize) starts in steps of theChunkSize, %% which is then reduced whenever an "out-of-memory" error is %% encountered. The default value is 25. %% insidesafe(..., theChunkSize, theVerboseFlag) displays progress %% information if theVerboseFlag is TRUE. % %% Copyright (C) 1999 Dr. Charles R. Denham, ZYDECO. %% All Rights Reserved. %% Disclosure without explicit written consent from the %% copyright owner does not constitute publication. % %% Version of 28-Apr-1999 20:06:47. %% Updated 13-Dec-2001 15:26:09. % %% N.B. -- Another scheme would be to triangulate the polygon, %% then to use "tsearch" to find points inside the convex hull, %% which would need to be trimmed to eliminate concave regions %% at the convex-hull boundary. Not a simple game. The first %% part is very fast, but the culling is dreadfully slow. % %DEFAULT_CHUNK_SIZE = 25; % <== Adjust as needed. %DEFAULT_VERBOSE_FLAG = ~~0; % Verbosity. % %% Demonstration. % %if nargin < 1, x = 'demo'; help(mfilename), end %if isequal(x, 'demo'), x = 100; end %if ischar(x), x = eval(x); end %if length(x) == 1 & nargin < 4 % px = [0 1 1 0 0]/2; % py = [0 0 1 1 0]/2; % n = x; % x = rand(1, n); % y = rand(size(x)); % tic % result = insidesafe(x, y, px, py, DEFAULT_CHUNK_SIZE, 0); % t = toc; % disp([' ## Elapsed time: ' num2str(t) ' s.']) % in = (result == 1); % on = (result == 0.5); % out = (result == 0); % h = plot(px, py, 'b-', x(in), y(in), 'g+', ... % x(on), y(on), 'b*', x(out), y(out), 'ro'); % % s = {'polygon'}; % if any(in), s{end+1} = 'inside'; end % if any(on), s{end+1} = 'on-edge'; end % if any(out), s{end+1} = 'outside'; end % legend(h, s{:}) % % figure(gcf) % set(gcf, 'Name', [mfilename ' ' int2str(n)]) % try, zoomsafe, catch, end % % return %end % %if nargin < 4, help(mfilename), return, end %if nargin < 5, theChunkSize = DEFAULT_CHUNK_SIZE; end %if nargin < 6, theVerboseFlag = DEFAULT_VERBOSE_FLAG; end % %px = px(:); py = py(:); %if length(px) ~= length(py) % error(' ## Polygon px and py must be same length.') %end % %if length(x) == 1, x = x + zeros(size(y)); end %if length(y) == 1, y = y + zeros(size(x)); end % %result = zeros(size(x)); %kmax = prod(size(result)); % %okay = 1; % %tic % %milestone = kmax - rem(kmax, theChunkSize); % %k = 0; %while k < kmax % if theVerboseFlag % remaining = kmax - k; % if k > 0 & remaining < milestone % time = remaining * toc / k; % disp([' ## ' mfilename ': Remaining: ' int2str(remaining) ... % ' points; ' int2str(time) ' seconds.']) % milestone = milestone - 4*theChunkSize; % end % end % i = k+1:min(k+theChunkSize, kmax); % try % result(i) = inpolygon(x(i), y(i), px, py); % k = k + theChunkSize; % catch % if findstr(lower(lasterr), 'memory') % lasterr('') % theChunkSize = floor(theChunkSize / 2); % if theVerboseFlag % disp([' ## ' mfilename ': Chunk-size reduced to: ' ... % int2str(theChunkSize)]) % tic % end % if theChunkSize < 1 % error([' ## ' mfilename ': Chunk-size reduced to zero.']) % end % else % okay = 0; % break % end % end %end % %if ~okay % if isempty(lasterr) % error([' ## Interrupted.']) % else % error([' ## ' lasterr]) % end %end % %if nargout > 0 % theResult = result; %else % disp(result) %end fclose(fout); disp(' ## Installing: "int2english.m" (text)') fout = fopen('int2english.m', 'w'); %function theResult = int2english(x) % %% int2english -- English name of an integer. %% int2english(x) returns or displays the English %% name of x, an integer, up to about 10^22. %% int2english('demo') demonstrates itself with %% a random integer. % %% Copyright (C) 1999 Dr. Charles R. Denham, ZYDECO. %% All Rights Reserved. %% Disclosure without explicit written consent from the %% copyright owner does not constitute publication. % %% Version of 29-Dec-1999 05:55:08. %% Updated 29-Dec-1999 07:36:13. % %if nargout > 0, theResult = []; end % %if nargin < 1, x = 'demo'; end % %if isequal(x, 'demo') % help(mfilename) % u = fix(rand(1, 1) * 100000); % v = feval(mfilename, u); % disp([' ## ' mfilename '(' int2str(u) ') = ' v]) % return %end % %if ischar(x), x = eval(x); end % %theNames = { % 'zero' % 'thousand' % 'million' % 'billion' % 'trillion' % 'quadrillion' % 'quintillion' % 'sextillion' % 'septillion' % 'octtillion' % 'nonillion' % 'decillion' %}; % %x = fix(x); %isNegative = x < 0; %x = abs(x); % %y = ''; % %if x < 20 % y = do1(x); %elseif x < 100 % y = do2(x); %else % k = 0; % while x > 0 % a = rem(x, 1000); % if a > 999 % disp([' ## Too big for Matlab "rem": ' num2str(x)]) % break % elseif a > 0 % temp = do3(a); % if k > 0 % temp = [temp ' ' theNames{k+1}]; % end % if ~isempty(y), y = [' ' y]; end % y = [temp y]; % end % k = k+1; % x = fix(x/1000); % end %end % %if isNegative, y = ['minus ' y]; end % %if nargout > 0 % theResult = y; %else % disp(y) %end % % %% ---------- do3 ---------- % % % %function y = do3(x) % %% do3 -- Name of an integer < 1000. %% do3(x) returns the name of integer x < 1000. % %if x < 100 % y = do2(x); %else % a = fix(x/100); % b = rem(x, 100); % y = [do1(a) ' hundred']; % if b > 0 % y = [y ' ' do2(b)]; % end %end % % %% ---------- do2 ---------- % % % %function y = do2(x) % %% do2 -- Name of an integer < 100. %% do2(x) returns the name of integer x < 100. % %theNames = { % 'zero' % 'ten' % 'twenty' % 'thirty' % 'forty' % 'fifty' % 'sixty' % 'seventy' % 'eighty' % 'ninety' %}; % %if x < 20 % y = do1(x); %else % a = fix(x/10); % b = rem(x, 10); % y = theNames{a+1}; % if b > 0 % y = [y ' ' do1(b)]; % end %end % % %% ---------- do1 ---------- % % % %function y = do1(x) % %% do1 -- Name of an integer < 20. %% do1(x) returns the name of integer x < 20. % %theNames = { % 'zero' % 'one' % 'two' % 'three' % 'four' % 'five' % 'six' % 'seven' % 'eight' % 'nine' % 'ten' % 'eleven' % 'twelve' % 'thirteen' % 'fourteen' % 'fifteen' % 'sixteen' % 'seventeen' % 'eighteen' % 'nineteen' %}; % %y = theNames{x+1}; fclose(fout); disp(' ## Installing: "julian2datenum.m" (text)') fout = fopen('julian2datenum.m', 'w'); %function theDateNum = julian2datenum(theJulian) % %% julian2datenum -- Convert Julian Day to Matlab datenum. %% julian2datenum(theJulian) converts theJulian decimal %% day to its equivalent Matlab datenum. The Julian %% day is referenced to midnight, not noon. % %% Copyright (C) 1998 Dr. Charles R. Denham, ZYDECO. %% All Rights Reserved. %% Disclosure without explicit written consent from the %% copyright owner does not constitute publication. % %% Version of 26-Oct-1998 15:49:22. % %if nargin < 1, help(mfilename), return, end % %t0 = datenum(1968, 5, 23) - 2440000; % May 23, 1968. % %result = theJulian + t0; % %if nargout > 0 % theDateNum = result; %else % disp(result) %end fclose(fout); disp(' ## Installing: "label1.m" (text)') fout = fopen('label1.m', 'w'); %function Label1(theLabel, theLocation) % %% Label1 -- Label the plot1 axes. %% Label1('theLabel', 'theLocation') places 'theLabel' at %% 'theLocation', one of {'xlabel', 'ylabel', 'zlabel', %% 'title'}; default = 'ylabel'. The "plot1" axes is %% used. % %% Copyright (C) 1997 Dr. Charles R. Denham, ZYDECO. %% All Rights Reserved. %% Disclosure without explicit written consent from the %% copyright owner does not constitute publication. % %% Version of 06-May-1997 15:48:32. % %if nargin < 1, help(mfilename), return, end %if nargin < 2, theLocation = 'ylabel'; end % %plot1 %feval(theLocation, theLabel) fclose(fout); disp(' ## Installing: "label2.m" (text)') fout = fopen('label2.m', 'w'); %function Label2(theLabel, theLocation) % %% Label2 -- Label the plot2 axes. %% Label2('theLabel', 'theLocation') places 'theLabel' at %% 'theLocation', one of {'xlabel', 'ylabel', 'zlabel', %% 'title'}; default = 'ylabel'. The "plot2" axes is %% used. % %% Copyright (C) 1997 Dr. Charles R. Denham, ZYDECO. %% All Rights Reserved. %% Disclosure without explicit written consent from the %% copyright owner does not constitute publication. % %% Version of 06-May-1997 15:48:32. % %if nargin < 1, help(mfilename), return, end %if nargin < 2, theLocation = 'ylabel'; end % %plot2 %feval(theLocation, theLabel) fclose(fout); disp(' ## Installing: "labelsafe.m" (text)') fout = fopen('labelsafe.m', 'w'); %function theResult = LabelSafe(theLabel) % %% LabelSafe -- Safe label for axes. %% LabelSafe('theLabel') modifies 'theLabel' by %% "escaping" instances of '\', '_', and '\^', %% after removing all instances of char(0) and '\0'. %% Existing escapes remain intact. The result is %% suitable as a title or axis label on a graph. %% LabelSafe (no argument) demonstrates itself. % %% Copyright (C) 1997 Dr. Charles R. Denham, ZYDECO. %% All Rights Reserved. %% Disclosure without explicit written consent from the %% copyright owner does not constitute publication. % %% Version of 01-Aug-1997 14:37:55. %% Version of 17-Nov-1997 13:35:12. % %if nargin < 1 % help(mfilename) % label = '\0_hello\world^'; % result = labelsafe(label); % begets(mfilename, 1, label, result) % return %end % %result = theLabel; % %if ~isempty(result) % result = strrep(result, char(0), ''); % result = strrep(result, '\0', ''); % % result = strrep(result, '\\', char(1)); % result = strrep(result, '\_', char(2)); % result = strrep(result, '\^', char(3)); % % result = strrep(result, '\', '\\'); % result = strrep(result, '_', '\_'); % result = strrep(result, '^', '\^'); % % result = strrep(result, char(1), '\\'); % result = strrep(result, char(2), '\_'); % result = strrep(result, char(3), '\^'); %end % %if ~isempty(result) % f = find(result ~= ' '); % if any(f) % result = result(f(1):f(length(f))); % end %end % %if nargout > 0 % theResult = result; % else % disp(result) %end fclose(fout); disp(' ## Installing: "lineno.m" (text)') fout = fopen('lineno.m', 'w'); %function [theLine, theName] = lineno(asString) % %% lineno -- Line-number of the calling function. %% [line, name] = lineno(asString) returns the line-number %% and function-name that called this function, or 0 and '' %% if called from the Matlab command-line prompt. If the %% asString flag is non-zero, the line-number is returned %% as a string; default flag = 0. % %% Copyright (C) 2000 Dr. Charles R. Denham, ZYDECO. %% All Rights Reserved. %% Disclosure without explicit written consent from the %% copyright owner does not constitute publication. % %% Version of 29-Nov-2000 15:20:37. %% Updated 03-May-2001 17:32:18. % %[stack, index] = dbstack; % %if length(stack) > 1 % stack = stack(2); %else % stack = []; % stack.line = 0; % stack.name = ''; %end % %line = stack.line; %name = stack.name; %linestr = ['line ' int2str(line) ' of "' name '"']; % %if nargout < 1 % disp(linestr) %elseif nargout < 2 % if nargin > 1 & asString % theLine = linestr; % else % theLine.line = line; % theLine.name = name; % end %else % theLine = line; % theName = name; %end fclose(fout); disp(' ## Installing: "ll.m" (text)') fout = fopen('ll.m', 'w'); %function ll(theDirectory) % %% ll -- Verbose directory listing. %% ll('theDirectory') lists the modification-date, %% byte-length, directory-flag, and name of each %% element in 'theDirectory', which defaults to %% the current directory. % %% Copyright (C) 2000 Dr. Charles R. Denham, ZYDECO. %% All Rights Reserved. %% Disclosure without explicit written consent from the %% copyright owner does not constitute publication. % %% Version of 18-Apr-2000 21:43:16. %% Updated 18-Apr-2000 22:04:00. % %if nargin < 1, theDirectory = pwd; end % %d = dir(theDirectory); % %maxname = 0; %for i = 1:length(d) % maxname = max(maxname, length(d(i).name)); %end % %blank = char(zeros(1, maxname) + abs(' ')); % %for i = 1:length(d) % nm = blank; % nm(1:length(d(i).name)) = d(i).name; % d(i).name = nm; %end % %maxbytes = 0; %for i = 1:length(d) % maxbytes = max(maxbytes, length(int2str(d(i).bytes))); %end % %blank = char(zeros(1, maxbytes) + abs(' ')); % %for i = 1:length(d) % by = int2str(d(i).bytes); % while length(by) < maxbytes % by = [' ' by]; % end % d(i).bytes = by; %end % %for i = 1:length(d) % if d(i).isdir % d(i).isdir = 'dir'; % else % d(i).isdir = ' '; % end %end % %if length(d) > 0 % disp(' ') % disp([' Directory: ' theDirectory]) % disp(' ') % for i = 1:length(d) % disp([' ' d(i).date ' ' d(i).bytes ' ' d(i).isdir ' ' d(i).name]) % end % disp(' ') %end fclose(fout); disp(' ## Installing: "loadsafe.m" (text)') fout = fopen('loadsafe.m', 'w'); %function [theResult, theLineNo] = loadsafe(theFilename) % %% loadsafe -- Load an ascii file. %% loadsafe('theFilename') loads the data from %% 'theFilename', an ascii file, alloting one %% row of the result for each line of the file. %% Warnings about questionable lines are posted. %% No-data entries are marked by NaN. Matlab %% comments and blank-lines are ignored. If %% no output argument is given, the result is %% assigned to the root-name of the file, as %% with regular Matlab "load". %% [theResult, theLineNo] = ... also returns the %% original line-numbers corresponding to the %% rows of theResult. % %% Copyright (C) 1998 Dr. Charles R. Denham, ZYDECO. %% All Rights Reserved. %% Disclosure without explicit written consent from the %% copyright owner does not constitute publication. % %% Version of 19-Oct-1998 22:36:04. %% Updated 20-Oct-1998 13:38:57. % %if nargout > 0, theResult = []; end % %if nargin < 1 % help(mfilename) % theFilename = '*'; %end % %if any(theFilename == '*') % [theFile, thePath] = uigetfile(theFilename, 'Select a File:'); % if ~any(theFile), return, end % if thePath(length(thePath) ~= filesep) % thePath = [thePath filesep]; % end % theFilename = [thePath theFile]; %end % %fp = fopen(theFilename, 'r'); % %count = 0; %bad = 0; %len = 0; %max_len = 0; %while 1 % s = fgetl(fp); % if isequal(s, -1), break, end % f = find(s == '%'); % if any(f), s(f(1):length(s)) = ''; end % while(length(s) > 0 & s(1) == ' ') % s(1) = ''; % end % if length(s) > 0 & s(1) ~= '%' % count = count+1; % t = ['[' s ']']; % bad_line = 0; % data = []; % eval('data = eval(t);', 'bad_line = 1;'); % if ~bad_line % max_len = max(max_len, length(data)); % else % bad = bad + 1; % disp([' ## ??? line ' int2str(count) ': ' s]) % end % end %end % %if bad > 0 % disp(' ') % disp([' ## Number of questionable lines: ' int2str(bad)]) % disp(' ') %end % %frewind(fp) % %result = nan * zeros(count, max_len); % %lineno = zeros(count, 1); %line = 0; % %count = 0; % %while (1) % s = fgetl(fp); % if isequal(s, -1), break, end % line = line + 1; % while(length(s) > 0 & s(1) == ' ') % s(1) = ''; % end % if length(s) > 0 & s(1) ~= '%' % count = count+1; % lineno(count) = line; % t = ['[' s ']']; % bad_line = 0; % data = []; % eval('data = eval(t);', 'bad_line = 1;'); % if ~bad_line & length(data) > 0 % result(count, 1:length(data)) = data; % end % end %end % %fclose(fp); % %if nargout > 0 % theResult = result; % theLineNo = lineno; %else % theName = theFilename; % f = find(theName == filesep); % if any(f), theName(1:f(length(f))) = ''; end % f = find(theName == '.'); % if any(f), theName(f(1):length(theName)) = ''; end % assignin('caller', theName, result) %end fclose(fout); disp(' ## Installing: "lsd.m" (text)') fout = fopen('lsd.m', 'w'); %function lsd(varargin) % %% lsd -- LS command with sub-directories indicated. %% lsd(...) lists the given directory, using "dir" %% syntax. Sub-directories are marked with "*". % %% Copyright (C) 2001 Dr. Charles R. Denham, ZYDECO. %% All Rights Reserved. %% Disclosure without explicit written consent from the %% copyright owner does not constitute publication. % %% Version of 24-Oct-2001 10:47:17. %% Updated 28-Mar-2002 11:16:41. % %MAX_LINE_WIDTH = 64; % Adjust as needed. %MAX_WHITE_SPACE = 2; % White-space between columns. %DIR_MARKER = '*'; % Appended to each directory name. % %try % Matlab 6+. % p = get(0, 'CommandWindowSize'); % Units = 'characters'. % MAX_LINE_WIDTH = p(1); %catch %end % %if nargin < 1 % d = dir; %else % d = dir(varargin{:}); %end % %if length(d) < 1 % disp('(No such items in directory.)') % return %end % %% Mark the directories. % %namelen = zeros(length(d), 1); %for i = 1:length(d) % if d(i).isdir % d(i).name = [d(i).name DIR_MARKER]; % end % namelen(i) = length(d(i).name); %end % %% Determine the number of columns, up to 10. % %for k = 1:10 % ncols = k; % mrows = fix((length(d)+ncols-1)/ncols); % if mrows > 0 % x = zeros(mrows, ncols); % x(1:length(namelen)) = namelen; % if sum(max(x)) > MAX_LINE_WIDTH - k*MAX_WHITE_SPACE % ncols = ncols-1; % break % end % else % ncols = ncols-1; % break % end %end % %% Number of rows. % %mrows = fix((length(d)+ncols-1)/ncols); % %% Put names into cell-array. % %c = cell([mrows ncols]); %for i = 1:mrows*ncols % c{i} = ''; % All names are strings. %end %for i = 1:length(d) % c{i} = d(i).name; %end % %temp = zeros(size(c)); %temp(1:length(namelen)) = namelen; %namelen = temp; % %% Pad with white-space between columns. % %if mrows == 1 % maxname = namelen + MAX_WHITE_SPACE; %else % maxname = max(namelen) + MAX_WHITE_SPACE; %end % %for j = 1:ncols-1 % for i = 1:mrows % s = c{i, j}; % s(end+1:maxname(j)) = ' '; % c{i, j} = s; % end %end % %% Display the table by rows. % %disp(' ') % %for i = 1:mrows % temp = c(i, :); % disp([temp{:}]) %end % %ndirs = sum([d.isdir]); %nfiles = sum(~[d.isdir]); % %disp(' ') %disp(['(' int2str(ndirs+nfiles) ' items total: ' ... % int2str(ndirs) ' dirs + ' ... % int2str(nfiles) ' files)']) %disp(' ') fclose(fout); disp(' ## Installing: "mailto.m" (text)') fout = fopen('mailto.m', 'w'); %function mailto(theAddress, theSubject, theBody, varargin) % %% mailto -- Compose e-mail in browser. %% mailto('address', 'subject', 'body') invokes %% the "mailto" facility of the local web-browser, %% using the given address, subject-line, and %% a short body, if any. If the body is surrounded %% by double-quotes, it will be treated as the name %% of a file to be inserted as the body. %% %% Note: the body may consist of more than one word, %% all assumed to be separated by one blank space. %% %% Note: use "%" with hexadecimal-code for non- %% printing characters, such as "%0D" for char(13) %% carriage- return. %% %% Macintosh: Maximum URL length is 255 characters. %% More can be added manually in the "mailto" window. % %% Copyright (C) 2001 Dr. Charles R. Denham, ZYDECO. %% All Rights Reserved. %% Disclosure without explicit written consent from the %% copyright owner does not constitute publication. % %% Version of 25-Sep-2001 16:54:54. %% Updated 04-Jan-2002 13:52:32. % %MACINTOSH_URL_MAX_LEN = 255; % Maximum. % %theURL = 'mailto:'; % %if nargin > 0 % if ~any(theAddress == '@') % theAddress = [theAddress '@usgs.gov']; % end % theURL = [theURL theAddress]; %end %if nargin > 1, theURL = [theURL '?subject=' theSubject]; end %if nargin > 2 % if length(varargin) > 0 % for i = 1:length(varargin) % theBody = [theBody ' ' varargin{i}]; % end % end % if theBody(1) == '"' & theBody(end) == '"' % filename = theBody(2:end-1); % fp = fopen(which(filename), 'r'); % theBody = char(fread(fp).'); % fclose(fp); % end % theBody = strrep(theBody, char(10), '%0A'); % Line-feed. % theBody = strrep(theBody, char(13), '%0D'); % Carriage-return. % theBody = strrep(theBody, char(32), '%20'); % Blank. % theURL = [theURL '&body=' theBody]; %end % %c = computer; %if any(findstr(c, 'MAC2')) % if length(theURL) > MACINTOSH_URL_MAX_LEN % theURL = theURL(1:MACINTOSH_URL_MAX_LEN); % end %end % %status = web(theURL); % %if any(status) % disp([' ## Web Status = ' int2str(status)]) %end fclose(fout); disp(' ## Installing: "marksafe.m" (text)') fout = fopen('marksafe.m', 'w'); %function marked = marksafe(varargin) % %% marksafe -- Mark data points in (x, y) plot. %% marksafe('demo') demonstrates itself, using random (x, y) %% data plotted with EraseMode = 'xor'. %% marksafe('on') enables marking, in which a mouse click %% on a plotted (x, y) point marks the site with a symbol. %% The z-data must be empty, or consist of TRUE (non-zero, %% marked) and FALSE (zero, not marked) values. %% marksafe(h) turns marking on for just the lines specified %% by the handles h. %% marksafe('off') turns marking off and removes the markers. %% The z-data of the targetted lines remain marked with 1. %% marksafe('clear') restores all the plotted data to visibility. %% marked = marksafe(h) returns the mark-vector (1 = marked; %% 0 = not marked) for the line whose handle is h. %% %% Also see: blinksafe. % %% Copyright (C) 2000 Dr. Charles R. Denham, ZYDECO. %% All Rights Reserved. %% Disclosure without explicit written consent from the %% copyright owner does not constitute publication. % %% Version of 12-Jan-2000 09:44:58. %% Updated 02-Feb-2000 23:45:50. % %% Note: It would be nice to vectorize this to %% handle more than one time-series simultaneously %% without having to think about it. % %MARKER_TAG = ['_' mfilename '_']; %MARKER_MARKER = '*'; %MARKER_SIZE = get(0, 'DefaultLineMarkerSize'); %MARKER_COLOR = [1 0 0]; %MARKER_BUTTONDOWNFCN = mfilename; %MARKER_ERASEMODE = 'xor'; % %% Demonstration. % %if nargin > 0 & isequal(varargin{1}, 'demo') % help(mfilename) % x = linspace(0, 1, 101); % y = sin(3*pi*x); % noise = 2*(rand(size(x)) - 0.5); % noise(abs(noise) < 0.95) = 0; % h = plot(x, y+noise, '-o', ... % 'MarkerSize', 4, 'EraseMode', 'xor'); % eval(mfilename) % if exist('zoomsafe', 'file') == 2 % eval('zoomsafe') % end % set(gcf, 'Name', [mfilename ' demo']) % if nargout > 0, marked = h; end % return %end % %% Get marks of a line. %% Requires a handle and an output variable. % %if nargout > 0 & nargin > 0 % vis = []; % h = varargin{1}; % if ischar(h), h = eval(h); end % if ishandle(h) % if isequal(get(h, 'Type'), 'line') % if ~isequal(get(h, 'Tag'), MARKER_TAG) % marked = ~~get(h, 'ZData'); % end % end % end % return %end % %% Actions: on, off, clear. % %if nargin > 0 & isempty(gcbo) % if ischar(varargin{1}) % theAction = varargin{1}; % switch theAction % case 'on' % varargin = {}; % case 'off' % h = findobj(gcf, 'Tag', MARKER_TAG); % if any(h), delete(h), end % return % case 'clear' % h = findobj(gcf, 'Tag', MARKER_TAG); % if any(h) % for i = 1:length(h) % u = get(h(i), 'UserData'); % z = get(u.handle, 'ZData'); % z(u.index) = u.z; % set(u.handle, 'ZData', z) % end % delete(h) % end % return % otherwise % disp([' ## No such action: "' theAction '"']) % return % end % end %end % %% Initialize. % %if isempty(gcbo) % if isempty(varargin) % h = findobj(gcf, 'Type', 'line'); % varargin{1} = h; % end % h = varargin{1}; % set(h, 'ButtonDownFcn', MARKER_BUTTONDOWNFCN) % for i = 1:length(h) % z = get(h(i), 'ZData'); % if isempty(z) % x = get(h(i), 'XData'); % z = zeros(size(x)); % set(h(i), 'ZData', z); % end % f = find(z); % make_marker(h(i), f) % end % return %end % %% Process a click. If clicking on the data, mark %% the closest data point. If clicking on a marker, %% restore the corresponding point. % %if isempty(varargin), varargin{1} = 'ButtonDownFcn'; end % %if length(varargin) > 0 & ischar(varargin{1}) % theEvent = varargin{1}; % switch lower(theEvent) % case 'buttondownfcn' % switch get(gcbo, 'Tag') % case '_marksafe_' % Delete the marker. % u = get(gcbo, 'UserData'); % z = get(u.handle, 'ZData'); % z(u.index) = u.z; % set(u.handle, 'ZData', z); % delete(gcbo) % otherwise % Create a marker. % p = get(gca, 'CurrentPoint'); % x0 = p(1, 1); % y0 = p(1, 2); % x = get(gcbo, 'XData'); % y = get(gcbo, 'YData'); % z = get(gcbo, 'ZData'); % if isempty(z), z = zeros(size(x)); end % % theMarker = get(gcbo, 'Marker'); % if isequal(theMarker, MARKER_MARKER) % MARKER_MARKER = 'o'; % end % if ~isequal(get(gcbo, 'Marker'), 'none') % MARKER_SIZE = 2 + get(gcbo, 'MarkerSize'); % end % if (1) % MARKER_ERASEMODE = get(gcbo, 'EraseMode'); % end % % dx = diff(get(gca, 'XLim')); % Scale to pixels. % dy = diff(get(gca, 'YLim')); % theOldUnits = get(gca, 'Units'); % set(gca, 'Units', 'pixels'); % thePosition = get(gca, 'Position'); % theWidth = thePosition(3); % theHeight = thePosition(4); % dx = dx / theWidth; % dy = dy / theHeight; % set(gca, 'Units', theOldUnits) % % d = abs((x*dy+sqrt(-1)*y*dx - (x0*dy+sqrt(-1)*y0*dx))); % % index = find(d == min(d)); % if any(index) % index = index(1); % if ~z(index) & 0 % u.handle = gcbo; % u.index = index; % u.z = z(index); % h = line(x(index), y(index),... % 'Marker', MARKER_MARKER, ... % 'MarkerSize', MARKER_SIZE, ... % 'MarkerFaceColor', 'none', ... % 'MarkerEdgeColor', MARKER_COLOR, ... % 'EraseMode', MARKER_ERASEMODE, ... % 'ButtonDownFcn', MARKER_BUTTONDOWNFCN, ... % 'UserData', u, ... % 'Tag', MARKER_TAG); % z(index) = 1; % set(gcbo, 'ZData', z) % else % h = make_marker(gcbo, index); % end % end % end % otherwise % disp(['## No such event: ' theEvent]) % end %end % % %% ---------- make_marker ---------- % % %function theResult = make_marker(h, index) % %% make_marker -- Create a marker. %% make_marker(h, index) places a mark on line h %% at the index, on behalf of the given mfile. % %% Copyright (C) 2000 Dr. Charles R. Denham, ZYDECO. %% All Rights Reserved. %% Disclosure without explicit written consent from the %% copyright owner does not constitute publication. % %% Version of 18-Jan-2000 14:11:55. %% Updated 18-Jan-2000 23:03:12. % %MARKER_TAG = ['_' mfilename '_']; %MARKER_MARKER = '*'; %MARKER_SIZE = get(0, 'DefaultLineMarkerSize'); %MARKER_COLOR = [1 0 0]; %MARKER_BUTTONDOWNFCN = mfilename; %MARKER_ERASEMODE = 'xor'; % %x = get(h, 'XData'); %y = get(h, 'YData'); %z = get(h, 'ZData'); %if isempty(z) % z = zeros(size(x)); %end % %theMarker = get(h, 'Marker'); %if isequal(theMarker, MARKER_MARKER) % MARKER_MARKER = 'o'; %end %if ~isequal(get(h, 'Marker'), 'none') % MARKER_SIZE = 2 + get(h, 'MarkerSize'); %end % %if (1), MARKER_ERASEMODE = get(h, 'EraseMode');end % %result = zeros(size(index)); % %for i = 1:length(index) % u.handle = h; % u.index = index; % u.z = z(index); % result(i) = line(x(index(i)), y(index(i)),... % 'Marker', MARKER_MARKER, ... % 'MarkerSize', MARKER_SIZE, ... % 'MarkerFaceColor', 'none', ... % 'MarkerEdgeColor', MARKER_COLOR, ... % 'EraseMode', MARKER_ERASEMODE, ... % 'ButtonDownFcn', MARKER_BUTTONDOWNFCN, ... % 'UserData', u, ... % 'Tag', MARKER_TAG); % z(index(i)) = 1; %end % %set(h, 'ZData', z) % %if nargout > 0, theResult = result; end fclose(fout); disp(' ## Installing: "movie1.m" (text)') fout = fopen('movie1.m', 'w'); %function theResult = Movie1(x1, x2, x3, x4, x5) % %% Movie1 -- Show a movie. %% Movie1(...) uses the movie() syntax to show a movie. %% It avoids the unpleasant behavior of the Matlab movie() %% routine, which shows the film first during loading, then %% again at the requested speed, or as fast as possible, %% whichever is slower. %% Movie1(nFrames) demonstrates itself with nFrames (default = 16), %% at four frames per second. %% theResult = Movie1(nFrames) returns a demonstration movie %% of nFrames. To show theResult, use "movie1(theResult)". % %% Copyright (C) 1997 Dr. Charles R. Denham, ZYDECO. %% All Rights Reserved. %% Disclosure without explicit written consent from the %% copyright owner does not constitute publication. % %% Version of 06-May-1997 10:24:44. %% Updated 09-Nov-1999 23:35:45. % %% Note: this routine needs to be updated %% to Matlab-5 syntax, using "varargin". % %if nargin < 1, help movie1, x1 = 16, end %if isstr(x1), x1 = eval(x1); end % %if nargin < 2 & length(x1) == 1 % help movie1 % nFrames = x1; % disp(' ## Create the movie.') % f = figure('Name', ['Movie1(' int2str(nFrames) ')']); % tic % theMovie = moviein(nFrames); % k = ceil(sqrt(nFrames)); % theFrame = zeros(k, k) + 24; % theImage = image(theFrame); % for j = 1:nFrames % theFrame = zeros(k, k) + 24; % theFrame(j) = 40; % set(theImage, 'CData', theFrame); % set(gca, 'Visible', 'off') % theText = text(1, 1, int2str(j), ... % 'HorizontalAlignment', 'center'); % theMovie(:, j) = getframe; % delete(theText) % end % toc % if nargout < 1 % disp(' ## Show the movie at 4 frames/second.') % t0 = clock; % speed = 4; % frames-per-second. % movie1(theMovie, 1, speed) % elapsed_time = etime(clock, t0); % average_frames_per_second = nFrames ./ elapsed_time % else % theResult = theMovie; % end % return %end % %theHandle = []; % %len = length(x1); %if len > 1 % theMovie = x1; % else % theHandle = x1; % theMovie = x2; %end % %nin = nargin; %if nargin < 3, x3 = 4; nin = nin+1; end %fps = x3; % %v = ''; %for i = 1:nargin % if i > 1, v = [v ' ,']; end % v = [v 'x' int2str(i)]; %end %v = ['movie(' v ')']; % %if isempty(theHandle), figure(gcf), end % %[m, nFrames] = size(theMovie); % %fps = x3; % Desired speed. %x3 = 1.5*x3; % First frame is usually slow. % %tic % Start the clock. %for j = 1:nFrames % if isempty(theHandle) % x1 = theMovie(:, j); % x2 = 1; % else % x2 = theMovie(:, j); % end % eval(v) % Show the frame. % t = toc; % Get elapsed time. % tic % Restart the clock. % speed = 1/t; %% disp(num2str(speed)) % x3 = x3 * fps / speed; % Adjust speed. %end fclose(fout); disp(' ## Installing: "mst.m" (text)') fout = fopen('mst.m', 'w'); %function theResult = mst(edges, costs) % %% mst -- Minimum spanning tree. %% mst('demo') calls "mst(10)". %% mst(nPoints) draws the minimum spanning tree for %% nPoints > 1 (random x-y pairs). Default = 10. %% The tree has the attractive property that it %% does not intersect itself. %% mst(edges, costs) returns indices of the minimum %% spanning tree for the edges [from to] of a %% connected graph, according to their corresponding %% costs. The edges connect vertices that are %% labeled [1:number-of-vertices]. The "minimum %% spanning tree" is the least costly graph that %% connects all the points. To obtain the %% maximum spanning tree, negate the costs. %% (Note: if the graph is not connected, the %% result will contain a minimal spanning %% tree for each piece.) %% mst(x, y) returns the minimum spanning tree %% for the (x, y) points, given as columns. %% mst(z) returns the minimum spanning tree %% for complex points z, given as a column. %% %% Reference: Isabel Beichl and Francis Sullivan, %% "In order to form a more perfect UNION," %% Computing in Science and Engineering, v. 3, %% n. 2, p. 60-64, March/April, 2001. The %% two local functions, "sfind" and "slink", %% are copied from that paper. The "sfind" %% strategy is due to Robert E. Tarjan. % %% Copyright (C) 2001 Dr. Charles R. Denham, ZYDECO. %% All Rights Reserved. %% Disclosure without explicit written consent from the %% copyright owner does not constitute publication. % %% Version of 02-Jul-2001 15:56:34. %% Updated 11-Mar-2003 15:14:02. % %if nargin < 1, help(mfilename), edges = 'demo'; end % %if isequal(edges, 'demo'), edges = 10; end % %if ischar(edges), edges = eval(edges); end % %% Demonstration. % %if nargin < 2 & length(edges) == 1 % npts = max(edges, 2); % z = rand(npts, 1) + sqrt(-1)*rand(npts, 1); % tic % result = feval(mfilename, z); % elapsed % from = result(:, 1); % to = result(:, 2); % x = real(z); % y = imag(z); % f = findobj(gcf, 'Type', 'axes'); % if any(f), delete(f), end % plot([x(from) x(to)].', [y(from) y(to)].', '-og') % title([mfilename ' ' int2str(npts)]) % xlabel x % ylabel y % set(gcf, 'Name', 'Minimum Spanning Tree', 'NumberTitle', 'off') % axis equal % try, zoomsafe, catch, end % figure(gcf) % if nargout > 0, theResult = result; end % return %end % %% Process (x, y) points, or z points (complex). % %if size(edges, 2) == 1 % if nargin == 1 % z = edges; % elseif nargin == 2 % x = edges; % y = costs; % z = x + sart(-1)*y; % end % npts = length(z); % [from, to] = meshgrid(1:npts, 1:npts); % from = from(:); % to = to(:); % f = find(from < to); % Unique edges only. % from = from(f); % to = to(f); % edges = [from to]; % costs = abs(z(to) - z(from)); %end % %% Sort the edges by their cost. % %[costs, indices] = sort(costs); %edges = edges(indices, :); % %from = edges(:, 1); %to = edges(:, 2); % %parent = 1:max(max(edges)); %rank = zeros(size(parent)); %keep = logical(zeros(size(parent))); % %% Join sub-trees until no more links to process. % %for i = 1:length(from) % x = sfind(parent, from(i)); % parent(from(i)) = x; % Acceleration strategy. % y = sfind(parent, to(i)); % parent(to(i)) = y; % Acceleration strategy. % if x ~= y % [parent, rank] = slink(x, y, parent, rank); % keep(i) = ~~1; % end %end % %result = edges(keep, :); % %% Check for disconnected graph, if desired. %% For a single connected graph, everyone %% will have the same root-parent. Isolated %% points are not considered part of the %% graph system. % %if (1) % p = zeros(size(parent)); % for i = 1:length(parent) % p(i) = sfind(parent, i); % end % if ~all(p == p(1)) % count = sum(diff(sort(p)) ~= 0) + 1; % disp([' ## Not a connected graph.']) % disp([' ## Contains ' int2str(count) ' independent graphs.']) % end %end % %% Sort indices for ease of reading. % %for i = 2:-1:1 % [ignore, indices] = sort(result(:, i)); % result = result(indices, :); %end % %if nargout > 0, theResult = result; end % % %% ---------- sfind ---------- % % % %function z = sfind(p, x) % %% sfind -- Root of a set. %% sfind(p, x) returns the root parent of the set %% containing index x, given parent-list p. The %% speed is O(lon(n)). % %y = x; % %while y ~= p(y) % y = p(y); %end % %z = p(y); % % %% ---------- slink ---------- % % % %function [p, rank] = slink(x, y, p, rank) % %% slink -- Link two sets. %% [p, rank] = slink(x, y, p, rank) links two sets, %% whose roots are x and y, using parent array p, %% and rank(x), a measure of the depths of the %% tree from root x. The speed is O(n). % %if rank(x) < rank(y) % p(x) = y; %else % if rank(y) < rank(x) % p(y) = x; % else % p(x) = y; % rank(y) = rank(y) + 1; % end %end % % %% ---------- elapsed ---------- % % % %function elapsed(thePrecision) % %% elapsed -- Print elapsed time. %% elapsed(thePrecision) displays the "toc" elapsed %% time, with the given precision, in decimal seconds %% (default = 1). Use "tic" to initiate the timer. % %% Copyright (C) 2001 Dr. Charles R. Denham, ZYDECO. %% All Rights Reserved. %% Disclosure without explicit written consent from the %% copyright owner does not constitute publication. % %% Version of 18-Jun-2001 06:41:43. %% Updated 18-Jun-2001 07:39:59. % %if nargin < 1, thePrecision = 1; end % %if ischar(thePrecision), thePrecision = eval(thePrecision); end % %try % t = fix(toc / thePrecision) * thePrecision; % disp([' ## Elapsed time: ' num2str(t) ' s.']) %catch % disp(' ## Please call "tic" first.') %end fclose(fout); disp(' ## Installing: "nanequal.m" (text)') fout = fopen('nanequal.m', 'w'); %function theResult = nanequal(x, y) % %% nanequal -- Equality despite NaN values. %% nanequal(x, y) considers NaNs to be equal %% when performing the ISEQUAL operation %% on arguments x and y. Note: ISEQUAL %% does not distinguish between "char", %% "double", and "logical" values, since %% they are almost always interchangeable. %% %% Also see: ISEQUAL, NANZERO. % %% Copyright (C) 2002 Dr. Charles R. Denham, ZYDECO. %% All Rights Reserved. %% Disclosure without explicit written consent from the %% copyright owner does not constitute publication. % %% Version of 20-Mar-2002 12:15:54. %% Updated 20-Mar-2002 12:15:54. % %if nargin < 2, help(mfilename), return, end % %result = isequal(x, y) | ... % (isequal(nanzero(x, 0), nanzero(y, 0)) & ... % isequal(nanzero(x, 1), nanzero(y, 1))); % %if nargout > 0 % theResult = result; %else % assignin('caller', 'ans', result) %end fclose(fout); disp(' ## Installing: "nanzero.m" (text)') fout = fopen('nanzero.m', 'w'); %function theResult = nanzero(x, theValue) % %% nanzero -- Convert all NaNs to zero or other value. %% nanzero(x, theValue) converts all NaNs in x %% (any class) to theValue (default = 0). %% %% Also see: ANYEQUAL, ANYEQUAL, ISEQUAL, NANEQUAL. % %% Copyright (C) 2002 Dr. Charles R. Denham, ZYDECO. %% All Rights Reserved. %% Disclosure without explicit written consent from the %% copyright owner does not constitute publication. % %% Version of 20-Mar-2002 11:48:24. %% Updated 20-Mar-2002 11:48:24. % %if nargin < 1, help(mfilename), return, end %if nargin < 2, theValue = 0; end % %switch class(x) %case 'cell' % for i = 1:prod(length(x)) % x{i} = feval(mfilename, x{i}); % end %case 'char' % x(isnan(x)) = theValue; %case 'double' % x(isnan(x)) = theValue; %case 'struct' % f = fieldnames(x); % for j = 1:length(f) % for i = 1:prod(length(x)) % y = feval(mfilename, getfield(x(i), f{j})); % x(i) = setfield(x(i), f{j}, y); % end % end %otherwise % disp([' ## Not able to process class: "' class(x) '"']) %end % %if nargout > 0 % theResult = x; %else % assignin('caller', 'ans', x) %end fclose(fout); disp(' ## Installing: "nofigs.m" (text)') fout = fopen('nofigs.m', 'w'); %function nofigs % %% nofigs -- Delete all existing figures. %% nofigs (no argument) deletes all existing %% figures without additional warning, %% including those with hidden-handles. % %% Copyright (C) 1996 Dr. Charles R. Denham, ZYDECO. %% All Rights Reserved. %% Disclosure without written explicit consent from the %% copyright owner does not constitute publication. % %% Updated 01-Nov-2001 14:39:30. % %flag = get(0, 'ShowHiddenHandles'); %set(0, 'ShowHiddenHandles', 'on') % %f = findobj(0); %f(f == 0) = []; %set(f, 'DeleteFcn', '') %f = findobj('Type', 'figure'); %set(f, 'CloseRequestFcn', '') %for i = 1:length(f) % theName = get(f(i), 'Name'); % delete(f(i)) % disp([' ## figure(' num2str(f(i)) ') -- [''' theName '''] -- deleted.']) %end % %set(0, 'ShowHiddenHandles', flag) fclose(fout); disp(' ## Installing: "partnames.m" (text)') fout = fopen('partnames.m', 'w'); %function theResult = partnames(theItem, theName) % %% partnames -- Part-names of an item. %% partnames(theItem) returns the depth-first list of %% the names of the parts of theItem, a Matlab entity. %% Prepend each part-name with the name of theItem in %% order to form the list of full-references that can %% be used to reconstruct theItem. %% partnames(theItem, 'theName') returns the part-names, %% with 'theName' prepended to each one. If '*', the %% "inputname" of theItem is used. %% partnames('demo') displays an example. %% %% Also see: parts(). % %% Copyright (C) 1997 Dr. Charles R. Denham, ZYDECO. %% All Rights Reserved. %% Disclosure without explicit written consent from the %% copyright owner does not constitute publication. % %% Version of 28-May-1998 08:47:39. % %if nargin < 1, help(mfilename), theItem = 'demo'; end % %if isequal(theItem, 'demo') % s = 'a{1}(2).b(3).c = pi;'; % disp([' ## ' s]) % disp([' ## ' mfilename '(a, ''a'') ==>']) % eval(s) % r = partnames(a, a); % for i = 1:length(r) % disp([' ## ' r{i}]) % end % return %end % %result = {}; % %switch class(theItem) %case {'char', 'double', 'uint8'} % result = {''}; %case 'struct' % f = fieldnames(theItem); % for j = 1:length(f) % x = getfield(theItem, f{j}); % s = partnames(x); % len = prod(size(theItem)); % for k = 1:len % r = s; % index = ''; % if len > 1, index = ['(' int2str(k) ')']; end % for i = 1:length(r) % r{i} = [index '.' f{j} r{i}]; % end % result = [result; r]; % end % end %case 'cell' % len = prod(size(theItem)); % for k = 1:len % index = ['{' int2str(k) '}']; % x = theItem{k}; % r = partnames(x); % for i = 1:length(r) % r{i} = [index r{i}]; % end % result = [result; r]; % end %otherwise % if isobject(theItem) % result = partnames(struct(theItem)); % else % disp([' ## ' mfilename '## Unknown class: ' class(theItem)]) % end %end % %% Prepend the item name. % %if nargin > 1 % if ~ischar(theName), theName = inputname(2); end % if isequal(theName, '*'), theName = inputname(1); end % if isempty(theName), theName = 'ans'; end % for i = 1:length(result) % result{i} = [theName result{i}]; % end %end % %if nargout > 0 % theResult = result; %else % disp(result) %end fclose(fout); disp(' ## Installing: "parts.m" (text)') fout = fopen('parts.m', 'w'); %function [theResult, theNames] = parts(theItem, theName) % %% parts -- Values and names of the parts of an item. %% parts(theItem) returns the values of the parts of %% theItem, in the form of a list. %% [theValues, theNames] = parts(...) also returns the %% list of corresponding part-names. %% [theValues, theNames] = parts(theItem, 'theName') also %% prepends 'theName' to each of the part-names. %% parts('demo') displays an example. %% %% Also see: partnames(). % %% Copyright (C) 1997 Dr. Charles R. Denham, ZYDECO. %% All Rights Reserved. %% Disclosure without explicit written consent from the %% copyright owner does not constitute publication. % %% Version of 28-May-1998 09:40:37. % %if nargin < 1, help(mfilename), theItem = 'demo'; end % %if isequal(theItem, 'demo') % s = 'a{1}(2).b(3).c = pi;'; % disp([' ## ' s]) % disp([' ## ' mfilename '(a, a) ==>']) % eval(s) % [theValues, theNames] = parts(a, a); % for i = 1:length(theValues) % disp([' ## ' mat2str(theNames{i}) ' ==> ' mat2str(theValues{i})]) % end % return %end % %theNames = partnames(theItem, '*'); %result = cell(size(theNames)); % %for i = 1:length(theNames) % result{i} = eval(theNames{i}, '''no-assigned-value'''); %end % %if nargout > 1 % if nargin < 2 % theNames = partnames(theItem); % else % if ~ischar(theName), theName = inputname(2); end % if isequal(theName, '*'), theName = inputname(1); end % if isempty(theName), theName = 'ans'; end % theNames = partnames(theItem, theName); % end %end % %if nargout > 0 % theResult = result; %else % disp(result) %end fclose(fout); disp(' ## Installing: "plot1.m" (text)') fout = fopen('plot1.m', 'w'); %function theResult = Plot1(varargin) % %% Plot1 -- Plot in first set of axes. %% Plot1(...) plots in the first set of axes, using %% the syntax of plot(). The 'YAxisLocation' is %% set to 'left'. %% Plot1 (no argument) switches to the first axes. %% Plot1('demo') demonstrates itself. % %% Copyright (C) 1997 Dr. Charles R. Denham, ZYDECO. %% All Rights Reserved. %% Disclosure without explicit written consent from the %% copyright owner does not constitute publication. % %% Version of 24-Apr-1997 10:59:23. % %if nargin == 1 & isequal(varargin{1}, 'demo') % delete(get(gcf, 'Children')) % x1 = 0:10; % x2 = 0:30; % y1 = 3 .* x1; % y2 = sin(2 .* pi .* x2 ./ max(x2)); % h1 = plot1(x1, y1, 'r+-'); % label1('Red x', 'xlabel') % label1('Red y (+ --- +)', 'ylabel') % set(gca, 'ButtonDownFcn', 'plot2, disp(''## Green Focus'')') % p = get(gca, 'Position'); % p(4) = 0.95 .* p(4); % set(gca, 'Position', p) % h2 = plot2(x2, y2, 'go-'); % label2('Green x', 'xlabel') % label2('Green y (o --- o)', 'ylabel') % set(gca, 'ButtonDownFcn', 'plot1, disp(''## Red Focus'')') % set(gcf, 'Name', 'Click To Switch Focus') % plot1 % return %end % %theAxes = sort(findobj(gcf, 'Type', 'axes')); %while length(theAxes) < 1 % theAxes = [theAxes axes]; %end %axes(theAxes(1)) % %if nargin > 0 % varargout = cell(1, nargout); % v = vargstr('plot', length(varargin), length(varargout)); % eval(v) %end % %theDefaultColor = get(0, 'DefaultAxesColor'); %if length(theAxes) > 1 % set(theAxes(2), 'Color', theDefaultColor) %end %set(theAxes(1), 'Color', 'none', ... % 'XAxisLocation', 'bottom', ... % 'YAxisLocation', 'left') % %if nargout > 0, theResult = varargout{1}; end fclose(fout); disp(' ## Installing: "plot2.m" (text)') fout = fopen('plot2.m', 'w'); %function theResult = Plot2(varargin) % %% Plot2 -- Plot in second set of axes. %% Plot2(...) plots in the second set of axes, %% using the syntax of plot(). The axes are %% superimposed on the first set of axes, and %% the 'YAxisLocation' is set to 'right'. %% Plot2 (no argument) switches to the %% second axes. % %% Copyright (C) 1997 Dr. Charles R. Denham, ZYDECO. %% All Rights Reserved. %% Disclosure without explicit written consent from the %% copyright owner does not constitute publication. % %% Version of 24-Apr-1997 10:59:23. % %theAxes = sort(findobj(gcf, 'Type', 'axes')); %while length(theAxes) < 2 % theAxes = [theAxes axes]; %end %axes(theAxes(2)) % %set(theAxes(2), 'Units', get(theAxes(1), 'Units')); %set(theAxes(2), 'Position', get(theAxes(1), 'Position')); % %if nargin > 0 % varargout = cell(1, nargout); % v = vargstr('plot', length(varargin), length(varargout)); % eval(v) %end % %theDefaultColor = get(0, 'DefaultAxesColor'); %set(theAxes(1), 'Color', theDefaultColor) %set(theAxes(2), 'Color', 'none') %theXAxisLocation = get(theAxes(1), 'XAxisLocation'); %theYAxisLocation = get(theAxes(1), 'YAxisLocation'); %if ~isequal(get(theAxes(1), 'XLim'), get(theAxes(2), 'XLim')) % switch theXAxisLocation % case 'bottom'; % theXAxisLocation = 'top'; % case 'top' % theXAxisLocation = 'bottom'; % otherwise % end %end %switch theYAxisLocation %case 'left'; % theYAxisLocation = 'right'; %case 'right' % theYAxisLocation = 'left'; %otherwise %end %set(theAxes(2), 'XAxisLocation', theXAxisLocation) %set(theAxes(2), 'YAxisLocation', theYAxisLocation') % %if nargout > 0, theResult = varargout{1}; end fclose(fout); disp(' ## Installing: "polyfitn.m" (text)') fout = fopen('polyfitn.m', 'w'); %function [p, err] = polyfitn(varargin) % %% polyfitn(f, order) -- ND polynomial fit. %% polyfitn('demo') demonstrates itself. %% polyfitn(N, order) demonstrates itself with N random %% points f(x, y) = (x - y).^order. Defaults: %% N = 10, order = 1. %% polyfitn(f, order) fits the data, a matrix arranged %% column-wise as [x y z ... f(x, y, z, ...)], to %% the given maximum order (default = 1). The %% result is an ND array. Each array index, minus %% one (1), represents the powers of the independent %% variables. For example, the index [1 2 3] would %% denote the x^0 + y^1 + z^2 term. Use "polyvaln" %% to evaluate the polynomial. %% polyfitn(x, y, ..., f, order) is an alternative %% syntax. %% [p, err] = ... also returns the error-norm %% of the fit. %% %% Also see: polyvaln. % %% Copyright (C) 2003 Dr. Charles R. Denham, ZYDECO. %% All Rights Reserved. %% Disclosure without explicit written consent from the %% copyright owner does not constitute publication. % %% Version of 22-Apr-2003 10:47:46. %% Updated 29-Apr-2003 13:15:41. % %% Strange behavior: polyfit(100, 9) does not work, %% whereas (99, 9) and (101, 9) do work. % %if nargin < 1 % help(mfilename) % varargin = {'demo'}; %end % %if nargin < 2 & isequal(varargin{1}, 'demo') % varargin{1} = 20; %end % %if ischar(varargin{1}) % varargin{1} = eval(varargin{1}); %end % %if nargin < 3 & length(varargin{1}) == 1 % N = varargin{1}; % x = rand(N, 1); % y = rand(size(x)); % order = 1; % if length(varargin) > 1 % order = varargin{2}; % end % if ischar(order), order = eval(order); end % f = (x - y).^order; % [pp, err] = feval(mfilename, x, y, f, order); % if nargout > 0, p = pp; end % xi = linspace(0, 1, 11); % yi = xi; % [xi, yi] = meshgrid(xi, yi); % g = zeros(size(xi)); % g(:) = polyvaln(pp, xi(:), yi(:)); % hold off % surf(xi, yi, g, ... % 'FaceColor', 'y', 'EraseMode', 'xor') % hold on % plot3(x, y, f, 'k*', 'EraseMode', 'xor') % hold off % xlabel X % ylabel Y % zlabel Z % title(['Error Norm: ' num2str(err)]) % figure(gcf) % set(gcf, 'Name', ... % [mfilename ' ' int2str(N) ' ' int2str(order)]) % return %end % %if length(varargin) > 2 % if length(varargin{end}) == 1 % order = varargin{end}; % data = [varargin{1:end-1}]; % else % order = 1; % data = [varargin{:}]; % end % if nargout > 1 % [p, err] = feval(mfilename, data, order); % else % p = feval(mfilename, data, order); % end % return %end % %data = varargin{1}; %if nargin > 1 % order = varargin{2}; %else % order = 0; %end % %[m, n] = size(data); % %sz = [order+1 order+1]; % %% Exponents for Vandermonde matrix. % %sub = cell(1, n-1); %[sub{:}] = ind2sub(sz, 1:prod(sz)); %for i = 1:length(sub) % sub{i} = sub{i}(:); %end %expon = [sub{:}] - 1; % %% Trim exponents to requested order. % %for k = 1:length(expon) % if sum(expon(k, :)) > order % expon(k, :) = NaN; % end %end % %% Vandermonde matrix. % %vander = zeros(m, prod(sz)); % %k = 0; %for i = 1:prod(sz) % x = data(:, 1:n-1); % k = k+1; % ex = expon(k, :); % if all(isfinite(ex)) % ex = repmat(ex, [m 1]); % x = data(:, 1:n-1) .^ ex; % vander(:, k) = prod(x, 2); % end %end % %% Solve. % %p = zeros([order+1 order+1]); % %warning off % Vander is habitually rank-deficient. %p(:) = vander \ data(:, end); %warning on % %if order == 0, p = p(1); end % %% Error-norm. % %if nargout > 1 % err = norm(polyvaln(p, data(:, 1:end-1)) - data(:, end)); %end fclose(fout); disp(' ## Installing: "polyvaln.m" (text)') fout = fopen('polyvaln.m', 'w'); %function y = polyvaln(p, varargin) % %% polyvaln -- Evalate an ND polynomial. %% polyvaln(p, loc) evaluates polynomial p %% at locations loc, a matrix whose columns %% represent [x y z ...]. The ND polynomial %% is arranged as in "polyfitn". %% polyvaln(p, x, y, z, ...) is an alternative %% syntax. %% %% Also see: polyfitn. % %% Copyright (C) 2003 Dr. Charles R. Denham, ZYDECO. %% All Rights Reserved. %% Disclosure without explicit written consent from the %% copyright owner does not constitute publication. % %% Version of 22-Apr-2003 14:51:04. %% Updated 22-Apr-2003 15:05:48. % %if nargin < 2, help(mfilename), return, end % %loc = [varargin{:}]; % %[m, n] = size(loc); %order = size(p, 2) - 1; %dims = length(size(p)); %sz = size(p); % %% Exponents for expansion. % %sub = cell(1, dims); %[sub{:}] = ind2sub(sz, 1:prod(sz)); %for i = 1:length(sub) % sub{i} = sub{i}(:); %end %expon = [sub{:}] - 1; % %% Trim exponents to requested order. % %for k = 1:length(expon) % if sum(expon(k, :)) > order % expon(k, :) = NaN; % end %end % %y = zeros(m, 1); % %k = 0; %for i = 1:prod(sz) % k = k+1; % ex = expon(k, :); % if all(isfinite(ex)) % ex = repmat(ex, [m 1]); % x = loc .^ ex; % x = prod(x, 2); % x = p(k) * x; % y = y + x; % end %end fclose(fout); disp(' ## Installing: "qsum1.m" (text)') fout = fopen('qsum1.m', 'w'); %function theResult = qsum1(varargin) % %% qsum1 -- Generalized summed products. %% qsum1(N) exercizes itself with four-dimensional arrays of %% length N in each direction (default = 1). %% qsum1(a, ia, b, ib, ..., iz, i_sums) multiplies and sums arrays %% a, b, ... together, whose compatible dimensions are labeled %% (named) by vectors ia, ib, ..., either integers or characters. %% The output dimensions are labeled by iz. Results are computed %% over the permuted output-indices, always summing along the %% directions given by i_sums. Thus, conventional matrix %% multiplication can be accomplished with the command: %% "qsum1(a, [1 2], b, [2 3], [1 3], [2])", same as %% "qsum1(a, 'ij', b, 'jk', 'ik', 'j')". %% NOTE: When summing along more than one direction, singleton %% dimensions may appear in the output, for which there is no %% corresponding input label. To specify a singleton-dimension %% in the output, use 0 (zero), or, with character labels, use %% char(0). Thus, the double-sum of the scalar product of %% two matrices can be accomplished with: %% "qsum(a, [1 2], b, [1 2], [0], [1 2])", same as %% "qsum(a, 'ij', b, 'ij', char(0), 'ij')". % %% Copyright (C) 2001 Dr. Charles R. Denham, ZYDECO. %% All Rights Reserved. %% Disclosure without explicit written consent from the %% copyright owner does not constitute publication. % %% Version of 14-Feb-2001 16:44:29. %% Updated 26-Feb-2001 14:20:41. % %if nargin < 1 % help(mfilename) % varargin{1} = 1; %end % %if length(varargin) < 2 % if isequal(varargin{1}, 'demo') % varargin{1} = 1; % end % if ischar(varargin{1}) % varargin{1} = eval(varargin{1}); % end %end % %% Demonstration. % %if nargin < 2 & length(varargin{1}) == 1 % n = varargin{1} % a = fix(rand(n, n, n, n)*10) + 1; % Results are 1-by-1 if n == 1. % b = fix(rand(n, n, n, n)*10) + 1; % c = fix(rand(n, n, n, n)*10) + 1; % if n < 2, a, b, c, end % tic % result = feval(mfilename, ... % a, [2 1 4 3], b, [4 3 2 1], c, [3 4 1 2], [4 3 2], [1]); % disp([' ## Elapsed time: ' num2str(toc) ' s.']) % if n < 2 % result % should_be = a(:) .* b(:) .* c(:) % end % return %end % %% Catalog the sizes of the input-variables. % %variables = varargin(1:2:end-2); %dimensions = varargin(2:2:end-2); %for i = 1:length(dimensions) % dimensions{i} = double(dimensions{i}); %end %lengths = []; %for j = 1:length(variables) % d = dimensions{j}; % 1x1x1x1 appears as 1-by-1 only. % while length(d) > length(lengths) % lengths(end+1) = 1; % end %end %for j = 1:length(variables) % s = size(variables{j}); % d = dimensions{j}; % 1x1x1x1 appears as 1-by-1 only. % for i = 1:length(s) % lengths(d(i)) = s(i); % end %end % %% Allocate the output-variable. % %dimensions_out = double(varargin{end-1}); %for i = 1:length(dimensions_out) % if dimensions_out(i) == 0 % lengths_out(i) = 1; % else % lengths_out(i) = lengths(dimensions_out(i)); % end %end %while length(lengths_out) < 2 % lengths_out(end+1) = 1; %end %result = zeros(lengths_out); % %% Get the summation directions. % %summation_directions = varargin{end}; % %% Build the subscripts for "subsref". % %subscripts = cell(size(variables)); %for k = 1:length(variables) % d = dimensions{k}; % subscripts{k} = cell(size(d)); % for j = 1:length(d) % subscripts{k}{j} = NaN; % Place-holder only. % end %end % %% Attach ":" to the summation directions. % %for k = 1:length(variables) % d = dimensions{k}; % for j = 1:length(d) % for i = 1:length(summation_directions) % if d(j) == summation_directions(i) % subscripts{k}{j} = ':'; % Summation direction. % end % end % end % subs = subscripts{k}; %end % %% Allocate the inner-product indexing structures. % %theStruct = []; %for k = length(variables):-1:1 % theStruct(k).type = '()'; % theStruct(k).subs = subscripts{k}; %end % %vars = cell(size(variables)); % Temporary variables. %indices= cell(size(lengths_out)); %count_out = prod(lengths_out); %moduli = [1 cumprod(lengths_out(1:end-1))]; % %% The big loop. Using one-dimensional indexing is slightly %% slower than using the multi-nested for-loops of the QSUM6 %% routine, but it has the advantage that it imposes no limit %% on the number of dimensions. % %for count = 1:count_out % %% remaining = (count_out - count + 1); %% if count == 1 | rem(remaining, 5000) == 0 %% disp([' ## Remaining: ' int2str(remaining)]) %% end % % % Convert one-dimensional index to subscripts. % % We do this brute-force, to save time. % %% [inds{:}] = ind2sub(lengths_out, count); % Slow. % % index = count-1; % for i = length(moduli):-1:1 % indices{i} = floor(index/moduli(i)) + 1; % index = rem(index, moduli(i)); % end % % % Fill-in the subscripts. About 50% of the % % run-time is spent in this section alone. % % It can be made faster by precomputing % % the locations of indices that need to % % change each time through the loop. % % for k = 1:length(variables) % d = dimensions{k}; % 7 percent. % s = theStruct(k).subs; % 7 percent. % for j = 1:length(d) % 9 percent. % switch ~ischar(s{j}) % 4 percent. % case 0 % otherwise % for i = 1:length(dimensions_out) % if d(j) == dimensions_out(i) % 11 percent. % s{j} = indices{i}; % 5 percent. % end % end % end % end % theStruct(k).subs = s; % 9 percent. % end % % % Get the subscripted variables. % % for k = 1:length(variables) % vars{k} = subsref(variables{k}, theStruct(k)); % 13 percent. % end % % % Multiply and sum. % % result(indices{:}) = prodsum(vars{:}); % 4 percent. % %end % %if nargout > 0 % theResult = result; %else % disp(result) %end % %% ---------- prodsum ---------- % % %function theResult = prodsum(varargin) % %% prodsum -- Sum of scalar products. %% prodsum(a, b, ...) returns sum(a(:) .* b(:) .* ...). % %% Copyright (C) 2001 Dr. Charles R. Denham, ZYDECO. %% All Rights Reserved. %% Disclosure without explicit written consent from the %% copyright owner does not constitute publication. % %% Version of 14-Feb-2001 17:32:48. %% Updated 21-Feb-2001 15:29:18. % %if nargin < 1, help(mfilename), return, end % %p = varargin{1}(:); % %for i = 2:length(varargin) % p = p .* varargin{i}(:); % 4 percent. %end % %p = sum(p); % %if nargout > 0 % theResult = p; %else % disp(p) %end fclose(fout); disp(' ## Installing: "rbrect.m" (text)') fout = fopen('rbrect.m', 'w'); %function theResult = rbrect(onMouseUp, onMouseMove, onMouseDown) % %% rbrect -- Rubber rectangle tracking (Matlab-4 and Matlab-5). %% rbrect('demo') demonstrates itself. %% rbrect('onMouseUp', 'onMouseMove', 'onMouseDown') conducts interactive %% rubber-rectangle tracking, presumably because of a mouse button press %% on the current-callback-object (gcbo). The 'on...' callbacks are %% automatically invoked with: "feval(theCallback, theInitiator, theRect)" %% after each window-button event, using the object that started this %% process, plus theRect as [xStart yStart xEnd yEnd] for the current %% rubber-rect. The callbacks default to ''. The coordinates of the %% rectangle are returned as [xStart yStart xEnd yEnd]. % %% Private interface: %% rbrect(1) is automatically called on window-button-motions. %% rbrect(2) is automatically called on window-button-up. % %% Copyright (C) 1997 Dr. Charles R. Denham, ZYDECO. %% All Rights Reserved. %% Disclosure without explicit written consent from the %% copyright owner does not constitute publication. % %% Version of 03-Jun-1997 15:54:39. %% Version of 11-Jun-1997 15:17:22. %% Version of 17-Jun-1997 16:52:46. % %global RBRECT_HANDLE %global RBRECT_INITIATOR %global RBRECT_ON_MOUSE_MOVE % %if nargin < 1, onMouseUp = 0; end % %if strcmp(onMouseUp, 'demo') % help rbrect % x = cumsum(rand(200, 1) - 0.45); % y = cumsum(rand(200, 1) - 0.25); % h = plot(x, y, '-r'); % set(h, 'ButtonDownFcn', 'disp(rbrect)') % figure(gcf), set(gcf, 'Name', 'RBRECT Demo') % return % elseif isstr(onMouseUp) % theMode = 0; % else % theMode = onMouseUp; % onMouseUp = ''; %end % % %if theMode == 0 % Mouse down. % if nargin < 3, onMouseDown = ''; end % if nargin < 2, onMouseMove = ''; end % if nargin < 1, onMouseUp = ''; end % theVersion = version; % isVersion5 = (theVersion(1) == '5'); % if isVersion5 % theCurrentObject = 'gcbo'; % else % theCurrentObject = 'gco'; % end % RBRECT_INITIATOR = eval(theCurrentObject); % switch get(RBRECT_INITIATOR, 'Type') % case 'line' % theColor = get(RBRECT_INITIATOR, 'Color'); % otherwise % theColor = 'black'; % end % RBRECT_ON_MOUSE_MOVE = onMouseMove; % pt = mean(get(gca, 'CurrentPoint')); % x = [pt(1) pt(1)]; y = [pt(2) pt(2)]; % RBRECT_HANDLE = line(x, y, ... % 'EraseMode', 'xor', ... % 'LineStyle', '--', ... % 'LineWidth', 2.5, ... % 'Color', theColor, ... % 'Marker', '+', 'MarkerSize', 13, ... % 'UserData', 1); % set(gcf, 'WindowButtonMotionFcn', 'rbrect(1);') % set(gcf, 'WindowButtonUpFcn', 'rbrect(2);') % theRBRect = [x(1) y(1) x(2) y(2)]; % if ~isempty(onMouseDown) % feval(onMouseDown, RBRECT_INITIATOR, theRBRect) % end % thePointer = get(gcf, 'Pointer'); % set(gcf, 'Pointer', 'circle'); % if isVersion5 & 0 % Disable for rbrect().. % eval('waitfor(RBRECT_HANDLE, ''UserData'', [])') % else % set(RBRECT_HANDLE, 'Visible', 'off') % Invisible. % eval('rbbox') % No "waitfor" in Matlab-4. % end % set(gcf, 'Pointer', thePointer); % set(gcf, 'WindowButtonMotionFcn', '') % set(gcf, 'WindowButtonUpFcn', '') % x = get(RBRECT_HANDLE, 'XData'); % y = get(RBRECT_HANDLE, 'YData'); % delete(RBRECT_HANDLE) % theRBRect = [x(1) y(1) x(2) y(2)]; % Scientific. % if ~isempty(onMouseUp) % feval(onMouseUp, RBRECT_INITIATOR, theRBRect) % end %elseif theMode == 1 % Mouse move. % pt2 = mean(get(gca, 'CurrentPoint')); % x = get(RBRECT_HANDLE, 'XData'); % y = get(RBRECT_HANDLE, 'YData'); % x(2) = pt2(1); y(2) = pt2(2); % set(RBRECT_HANDLE, 'XData', x, 'YData', y) % theRBRect = [x(1) y(1) x(2) y(2)]; % if ~isempty(RBRECT_ON_MOUSE_MOVE) % feval(RBRECT_ON_MOUSE_MOVE, RBRECT_INITIATOR, theRBRect) % end %elseif theMode == 2 % Mouse up. % pt2 = mean(get(gca, 'CurrentPoint')); % x = get(RBRECT_HANDLE, 'XData'); % y = get(RBRECT_HANDLE, 'YData'); % x(2) = pt2(1); y(2) = pt2(2); % set(RBRECT_HANDLE, 'XData', x, 'YData', y, 'UserData', []) %else %end % %if nargout > 0, theResult = theRBRect; end fclose(fout); disp(' ## Installing: "rect.m" (text)') fout = fopen('rect.m', 'w'); %function [theResult, theStraightness] = rect(z, ntimes, n1, n2, n3, n4) % %% rect -- Map contour points onto a rectangle. %% rect(z, ntimes, n1, n2, n3, n4) maps the complex z %% contour points, in counter-clockwise sequence, %% onto a unit-rectangle, using ntimes iterations. %% The n1..n4 are the indices of the four %% corner-points. %% [theResult, theStraightness] = rect(...) also %% returns a measure of straightness, which %% should be very close to 1. Convergence can be %% checked by computing the norm of the difference %% of two successive iterations. %% rect(n, ntimes) demonstrates itself with n random %% points (default is 40) and ntimes iterations %% (default is sqrt(n)). The corner-positions %% are chosen randomly. %% %% Reference: Ives, D.D. and R.M. Zacharias, Conformal %% mapping and orthogonal grid generation, Paper No. %% 87-2057, AIAA/SAE/ASME/ASEE 23rd Joint Propultion %% Conference, San Diego, California, June, 1987. % %% The present routine is modified slightly to avoid %% zero-divides. % %% Copyright (C) 1997 Dr. Charles R. Denham, ZYDECO. %% All Rights Reserved. %% Disclosure without explicit written consent from the %% copyright owner does not constitute publication. % %% Version of 05-Jun-1998 09:07:06. %% Updated 20-Oct-1998 22:21:56. %% Revised 26-Oct-1998 14:29:11. % %if nargin < 1, help(mfilename), z = 'demo'; end % %if isequal(z, 'demo'), z = 40; end % %if isstr(z), z = eval(z); end % %if length(z) == 1 % if nargin < 2, ntimes = ceil(sqrt(z)); end % if ischar(ntimes), ntimes = eval(ntimes); end % n = fix((z+3)/4) .* 4; % x = rand(1, n) - 0.5; % y = rand(1, n) - 0.5; % z = x + sqrt(-1) .* y; % [a, ind] = sort(angle(z)); % z = z(ind); % z = z + exp(sqrt(-1).*a); % z = 10 * z; % if (0) % nn = round([1 n/4 2*n/4 3*n/4]); % else % Random corner-points. % [s, index] = sort(rand(1, length(z)-1)); % nn = [1 (sort(index(1:3))+1)]; % end % delete(get(gcf, 'Children')) % subplot(1, 2, 1) % plot(real(z), imag(z), '-+', real(z(nn)), imag(z(nn)), 'ro') % title('Original') % axis equal % drawnow % figure(gcf) % et = 0; % result = z; % for iter = 1:ntimes % z = result; % tic % [result, straightness] = rect(z, 1, nn); % if ~isfinite(straightness), break, end % et = et + toc; % subplot(1, 2, 2) % plot(real(result), imag(result), '-+', ... % real(result(nn)), imag(result(nn)), 'ro') % title(['Mapped by RECT: iteration #' int2str(iter)]) % axis equal % figure(gcf) % drawnow % end % title(['Mapped by RECT']) % disp([' ## Elapsed time: ' int2str(et) ' seconds.']) % if nargout > 0 % theResult = result; % theStraightness = straightness; % else % disp([' ## Straightness: ' num2str(straightness)]) % end % zoomsafe % s = [mfilename ' ' int2str(n) ' ' int2str(ntimes)]; % set(gcf, 'ButtonDownFcn', s) % return %end % %z = z(:); %if z(1) == z(end), z(end) = []; end %n = length(z); % %if nargin < 2, ntimes = 1; end %if nargin == 3 & length(n1) == 4 % n4 = n1(4); % n3 = n1(3); % n2 = n1(2); % n1 = n1(1); %else % if nargin < 3, n1 = 1; end % if nargin < 4, n2 = n1 + fix(n/4); end % if nargin < 5, n3 = n2 + fix(n/4); end % if nargin < 6, n4 = n3 + fix(n/4); end %end % %nn = [n1 n2 n3 n4]; % %r = zeros(size(z)); %t = zeros(size(z)); % %track_errors = 0; % %for iter = 1:ntimes % % if ntimes > 10 % disp([' ## Iterations remaining: ' int2str(ntimes-iter+1)]) % end % % z_old = z; % % for i = 1:n % The big loop. % if rem(n-i+1, 100) == 0 & 0 % disp([' ## Remaining: ' int2str(n-i+1)]) % end % im = n - rem(n-i+1, n); % Index of previous point. % ip = 1 + rem(i, n); % Index of next point. % zd = 1; % if z(ip) ~= z(i) % zd = (z(im) - z(i)) ./ (z(ip) - z(i)); % else % zd = (z(im) - z(i)) ./ sqrt(eps); % end % alpha = atan2(imag(zd), real(zd)); % Current angle. % if alpha < 0 % alpha = alpha + 2 .* pi; % elseif alpha == 0 % alpha = sqrt(eps); % end % pwr = pi ./ alpha; % Power for pi outcome. % if any(i == nn) % Corners. % if z(im) ~= z(i) % zd = (z(im) - z(i)) ./ abs(z(im) - z(i)); % Unit-vector. % else % zd = 1; % end % z = sqrt(-1) .* z ./ zd; % pwr = pwr ./ 2; % Power for pi/2 outcome. % end % %% Compute the unwrapped phases. % % j = 2:n; % zd = z(rem(j+i-2, n)+1) - z(i); % r(j) = abs(zd); % t(j) = atan2(imag(zd), real(zd)) - 6.*pi; % if (1) % t = unwrap1(t); % Local subroutine. % else % t = unwrap(t); % Matlab subroutine. % end % temp = t(2:n).*pwr; % % pmax = max(temp); % pmin = min(temp); % if pmax ~= pmin % pwr = min(pwr, 1.98 .* pi .* pwr ./ (pmax - pmin)); % end % z(i) = 0; % % z(rem(j+i-2, n)+1) = r(j).^pwr.*exp(sqrt(-1).*t(j).*pwr); % zd = 1 ./ (z(n2) - z(n1)); % Possible zero-divide. % z0 = z(n1); % z = (z - z0) .* zd; % end % %% Compute the straightness of the perimeter %% by comparing the perimeter along the data %% with the perimeter just around the corners. %% The mapping may appear to be straight %% without actually being rectangular. % % p1 = sum(abs(diff([z(nn); z(nn(1))]))); % p2 = sum(abs(diff([z; z(1)]))); % straightness = p1 ./ p2; % %% Norm of changes as measure of convergence. %% The mapping may converge without actually %% producing a rectangular shape. % % change = 2 .* norm(z - z_old) ./ norm(z + z_old); % %% Progress report. % % s = round(1000 .* straightness) ./ 10; % c = round(1000 .* change) ./ 10; % if nargout < 2 & 0 % disp([' ## ' num2str(s) ' % straight; ' num2str(c) ' % change.']) % end % %end % %if track_errors > 0 % Not ever checked. % disp([' ## Tracking errors: ' int2str(track_errors)]) %end % %if nargout > 0 % theResult = z; % theStraightness = straightness; %else % disp(z), straightness %end % % %function theResult = unwrap1(p) % %% unwrap1 -- Unwrap radian phases modulo 2*pi. %% unwrap1(p) performs a modulo-2*pi unwrapping %% of the phases of radian values p, working %% columnwise if p is a matrix. %% unwrap1 (no argument) demonstrates itself. % %% Copyright (C) 1998 Dr. Charles R. Denham, ZYDECO. %% All Rights Reserved. %% Disclosure without explicit written consent from the %% copyright owner does not constitute publication. % %% Version of 09-Nov-1998 11:02:40. % %if nargin < 1, help(mfilename), p = 'demo'; end % %if isequal(p, 'demo'), p = 24; end % %if ischar(p), p = eval(p); end % %if length(p) == 1 % m = p; % p = rand(m, 1)*2*pi; % r = unwrap1(p); % t = (1:m).'; % plot(t, p, ':o', t, r, '-o') % legend('original', 'unwrapped') % title('unwrap1 demo') % xlabel('time'), ylabel('phase (radians)') % figure(gcf) % return %end % %[oldM, n] = size(p); %if oldM == 1, p = p.'; end %[m, n] = size(p); % %mn = ones(m, 1) * min(p); % Column-wise minima. %p = rem(p-mn, 2*pi) + mn; % Flatten to 2*pi range. %d = [p(1, :); diff(p)]; % Differences. %up = (d > pi); down = (d <= -pi); % Find big jumps. %c = cumsum(down-up)*2*pi; % Corrections. %result = p+c; % %if oldM == 1, result = result.'; end % %if nargout > 0 % theResult = result; %else % disp(result) %end fclose(fout); disp(' ## Installing: "rect2grid.m" (text)') fout = fopen('rect2grid.m', 'w'); %function [result, error_norm] = rect2grid(z, zrect, ... % theCorners, theSize) % %% rect2grid -- Orthogonal grid from RECT result. %% [result, error_norm] = rect2grid(z, zrect, theCorners, theSize) %% produces a curvilinear orthogonal grid by interpolating the %% complex contour z, using zrect, the result of applying the %% conformal mapper RECT to z for theCorners (indices). If zrect %% is empty, the RECT routine is called to compute it. If zrect %% is a scalar, that number of RECT iterations will be performed. %% The size of the w output grid (complex matrix), including the %% perimeter, is determined by theSize. The returned error_norm %% is the norm of the respective laplacians. %% rect2grid(nPoints) demonstrates itself with a random z contour %% of nPoints (default = 20). % %% Copyright (C) 1998 Dr. Charles R. Denham, ZYDECO. %% All Rights Reserved. %% Disclosure without explicit written consent from the %% copyright owner does not constitute publication. % %% Version of 21-Oct-1998 20:50:16. %% Updated 23-Jun-2000 14:29:17. % %% Note: The splined interpolations tend to be too wild %% for general use here. The safest method is to sample %% the z curve at very fine intervals, then use linear %% interpolation. %% %% Note: Presently, we apply rect to the existing boundary %% at equal-intervals along the edges, then interpolate %% to even-intervals in the rect domain, then solve the %% Poisson system, then interpolate back to the original %% spacing. It might make better sense to iteratively %% apply rect, then resample the original boundary, until %% the rect-domain itself shows more or less equal-spacing %% along all edges. We would adjust one edge before moving %% to the next. Then, we would solve the Poisson system, %% then interpolate backwards as before. The aim is to avoid %% crowding of mapped points in the rect-domain, where things %% are often not very smooth. If we have to interpolate, %% let it be restricted to the original domain. % %% Note: The rectangular mapping itself is based on a boundary %% composed of linear segments, which implies that any subsequent %% interpolations within the Poisson solution-grid should be done %% bi-linearly, rather than via splines. (The bilinear %% interpolants of a rectangular grid have Laplacian = 0 %% automatically.) By extension, the best way to interpolate %% a Poisson grid is linearly if we are taking the FFT approach. % %% Note: We should think about an iterative scheme is which the %% points to be mapped are adjusted until the mapping yields %% a more-or-less equally-spaced distribution. It will be %% tricky, because interated-splines are badly behaved. % %if (0) % theInterpFcn = 'splineq'; % Interpolation function. % theInterpMethod = 1; % interpolation method. %else % theInterpFcn = 'interp1'; % Interpolation function. % theInterpMethod = 'linear'; % interpolation method. %end % %if nargin < 1, help(mfilename), z = 'demo'; end %if isequal(z, 'demo'), z = 20; end %if ischar(z), z = eval(z); end % %if length(z) == 1 % n = max(z, 4); % z = rand(n, 1) + sqrt(-1)*rand(n, 1); % z = z - mean(z); % a = angle(z); % [a, i] = sort(a); % jitter = 0.1; % z = (1 + jitter * rand(size(a))) .* exp(sqrt(-1)*a); % [ignore, nn] = sort(rand(1, length(z)-1)); % theCorners = sort([1 nn(1:3)+1]); % % k = 1; ktest = n*sqrt(n); % while k < ktest % k = 2*k; % end % theSize = [k k] + 1; % % ztemp = z; % ztemp(end+1) = z(1); % z = []; % c = [theCorners length(ztemp)]; % theCorners = []; % % zplot = []; % % for i = 1:4 % j = c(i):c(i+1); % [ji, pp] = splineq(j, ztemp(j), n, 1); % zitemp = ppval(pp, ji); % zitemp(end) = []; % theCorners = [theCorners length(z)+1]; % z = [z zitemp]; % end % % if (0) % Set to 1 to see orthogonality. % z = rect(z, ceil(sqrt(n)), theCorners); % end % % tic % % FLAG = 0; % % zrect = []; % % if FLAG % zrect = rect(z, ceil(sqrt(n)), theCorners); % end % % [w, err] = rect2grid(z, zrect, theCorners, ceil(theSize/2)); % % disp([' ## Elapsed time: ' num2str(toc) ' seconds.']) % % if ~isempty(w) % u = real(w); v = imag(w); % u_err = real(err); v_err = imag(err); % subplot(1, 1, 1) % if FLAG, subplot(1, 2, 1), end % hold off % h = plot(u, v, 'g-', u.', v.', 'b-'); % hold on % z(end+1) = z(1); % x = real(z); y = imag(z); % plot(x, y, 'bo', ... % x(theCorners), y(theCorners), 'ro', ... % x(theCorners(1)), y(theCorners(1)), 'r*') % hold off % xlabel('x'), ylabel('y') % theCommand = [mfilename ' ( ' int2str(n) ' )']; % title(theCommand) % set(gcf, 'ButtonDownFcn', theCommand) % figure(gcf) % axis equal % zoomsafe 0.9, zoomsafe % if FLAG % subplot(1, 2, 2) % plot(real(zrect), imag(zrect), '-o') % axis equal % zoomsafe 0.9, zoomsafe % end % end % error_norm = [real(err) imag(err)]; % if nargout > 0 % result = w; % else % disp([' ## error_norm = ' ... % sprintf('%0.4g %0.4gi', error_norm)]) % end % return %end % %% Check for mex-files "mexrect" and "mexsepeli". % %hasMex = (exist('mexrect', 'file') == 3) & ... % (exist('mexsepeli', 'file') == 3); % %hasMex = 0; % Note this override. % %% If no actual "zrect" is given, apply RECT until %% the straightness of the result deviates from %% 1.0 by no more than 0.001 percent. % %if length(zrect) < 2 % if length(zrect) == 1 % ntimes = zrect; % else % ntimes = ceil(sqrt(length(z))); % end % zrect = z(:); % % tolerance = 0.001; % tolerance = 0.00001; % <== tolerance. % % for i = 1:ntimes % if ~hasMex % [zrect, straight] = feval('rect', zrect, 1, ... % theCorners); % else % zrect = feval('mexrect', zrect, length(zrect), ... % theCorners(1), theCorners(2), theCorners(3), ... % theCorners(4)); % ztemp = zrect; % ztemp(end+1) = ztemp(1); % ctemp = theCorners; % ctemp(end+1) = ctemp(1); % num = sum(abs(diff(ztemp(ctemp)))); % den = sum(abs(diff(ztemp))); % straight = num./den; % end % if norm(1-straight) <= tolerance, break, end % disp([' ## RECT Iteration ' int2str(i) ... % ': straightness = ' num2str(straight*100) ... % ' percent.']) % end % %% Verbose quality of mapping. % % if (0) % hello % non_straight_percent = 100*(1-straight) % d13 = abs(diff(zrect(theCorners([1 3])))); % d24 = abs(diff(zrect(theCorners([2 4])))); % non_rect_percent = 100*2*abs((d13-d24)/(d13+d24)) % fig = gcf; % f = findobj('Type', 'figure', 'Tag', mfilename); % if isempty(f) % f = figure('Name', mfilename', 'Tag', mfilename); % end % figure(f) % plot(real(zrect), imag(zrect), '-o', ... % real(zrect(theCorners(1))), ... % imag(zrect(theCorners(1))), '*') % set(gca, 'XLim', [-0.1 1.1]*max(real(zrect)), ... % 'YLim', [-0.1 1.1]*max(imag(zrect))) % figure(fig) % drawnow % end % % if norm(1-straight) > tolerance % disp([' ## rect2grid: Conformal mapping not successful']) % disp([' after ' int2str(ntimes) ... % ' iterations.']) % if nargout > 0, result = []; error_norm = []; end % return % end %end % %% Make zrect perfectly rectangular: not necessary. % %if (0) % x = real(zrect); x = [x(:); x(1)]; % y = imag(zrect); y = [y(:); y(1)]; % c = [theCorners(:); length(x)].'; % y(c(1):c(2)) = 0; % x(c(2):c(3)) = 1; % y(c(3):c(4)) = mean(y(c(3):c(4))); % x(c(4):c(5)) = 0; % zrect = x(1:end-1) + sqrt(-1)*y(1:end-1); %end % %% Desired size. % %if length(theSize) == 1, theSize = theSize * [1 1]; end % %m = theSize(1); n = theSize(2); % %% Get indices of matrix perimeter. % %temp = zeros(theSize); %temp(:) = 1:prod(theSize); % %ind = []; %ind = [ind; temp(1:m-1, 1)]; %ind = [ind; temp(m, 1:n-1).']; %ind = [ind; temp(m:-1:2, n)]; %ind = [ind; temp(1, n:-1:1).']; % %% Interpolate around the "zrect" boundary %% as a function of distance along the physical %% boundary. % %rdist = [0; cumsum(abs(diff([zrect(:); zrect(1)])))]; %rdist = rdist - min(rdist); rdist = rdist / max(rdist); % % %z(end+1) = z(1); %x = real(z); %y = imag(z); % %c = [theCorners(:); length(x)].'; % Physical and mapped corners. %d = cumsum([1 m-1 n-1 m-1 n-1]); % Corners around the matrix. % %xi = zeros(size(ind)); %yi = zeros(size(ind)); % %for i = 1:4 % j = c(i):c(i+1); % k = d(i):d(i+1); % rd = rdist(j); rd = rd - min(rd); rd = rd / max(rd); % xx = x(j); % yy = y(j); % dd = k; dd = dd - min(dd); dd = dd / max(dd); % % TESTING = 1; % <== NOTE. % TESTING = 0; % <== NOTE. % % if TESTING % [ki, pp] = splineq(j, z(j), length(k), 1); % zi = ppval(pp, ki); % xi(k) = real(zi); % yi(k) = imag(zi); % else % xi(k) = feval(theInterpFcn, rd, xx, dd, theInterpMethod).'; % yi(k) = feval(theInterpFcn, rd, yy, dd, theInterpMethod).'; % end % %end % %if (0) % hello(mfilename) % c, y, d = diff(y); %end % %% Sprinkle interpolated values along the perimeter. % %u = zeros(theSize); v = zeros(theSize); %u(ind) = xi; v(ind) = yi; % %% Aspect ratio of the rectangle. %% NOTE: When we solve via FFT, the aspect-ratio of the %% rectangle needs to be accomodated by adjusting size %% [m n] so that the grid-cells are roughly square. %% If the aspect-ratio is 1.72, for example, then %% the size of our solution plane (u and v) should %% be of ratio 100-by-172, not the 100-by-100 %% used at present. (We can use the Matlab "rat" %% function to help select the actual size.) %% So, use the aspect ratio to determine the number %% of interpolated points around the perimeter, %% populate a solution matrix of similar ratio, %% solve, interpolate to to the array size we %% actually want. % %if (1) % dx = 1; dy = 1; % Square. %else % dx = abs(zrect(2)-zrect(1)) / m; % Rectangle. % dy = abs(zrect(3)-zrect(2)) / n; % Rectangle. %end % %% Solve Laplace's equation inside the boundary. At this %% stage, it is slightly advantageous to use arrays u and %% v whose sizes are a power-of-two plus one. % %if ~hasMex % isSlope = 0; % u = fps(u, isSlope, dx, dy); % v = fps(v, isSlope, dx, dy); %else % Use MEXSEPELI. % l2 = m-1; % m2 = n-1; % seta = linspace(0, 1, n); % sxi = linspace(0, 1, m); % [u, v] = feval('mexsepeli', u, v, l2, m2, seta, sxi); %end % %w = u + sqrt(-1).*v; % %if nargout > 0 % result = w; %else % disp(w) %end % %if nargout > 1 % del2_u = 4*del2(u); % err_norm_u = norm(del2_u(2:end-1, 2:end-1)); % del2_v = 4*del2(v); % err_norm_v = norm(del2_v(2:end-1, 2:end-1)); % error_norm = err_norm_u + sqrt(-1).*err_norm_v; %end fclose(fout); disp(' ## Installing: "save4.m" (text)') fout = fopen('save4.m', 'w'); %function save4(varargin) % %% save4 -- Versatile "save", using Matlab v4 Mat-file. %% save4('demo') exercizes itself with "save4(10)". %% save4(N) exercizes itself with N-by-N random data. %% save4('filename') saves all compatible variables %% to "filename". Default filename = 'matlab.mat'; %% default extension = '.mat'. %% save4('filename', 'var1', 'var2', ..., '-precision', ... %% '-asis', '-append') saves the given variables %% (double, char, and sparse arrays) in a Matlab v4 %% Mat-file, using the specified precision, plus %% other options: %% %% '-double' Default for numbers. %% '-single' %% '-long' %% '-short' %% '-ushort' Default for strings. %% '-uchar' %% %% '-asis' Store integers without packing. %% '-append' Append variables to existing file. %% %% Note: Multi-dimensional arrays are cast to two-dimensions. %% Note: Experience with NaN and Inf as integers may vary. %% %% Also see: SAVE, LOAD. % %% Copyright (C) 2002 Dr. Charles R. Denham, ZYDECO. %% All Rights Reserved. %% Disclosure without explicit written consent from the %% copyright owner does not constitute publication. % %% Version of 17-Jan-2002 09:49:50. %% Updated 18-Jan-2002 11:45:34. % %% Demonstration. % %if length(varargin) == 1 & isequal(varargin{1}, 'demo') % help(mfilename) % varargin{1} = 10; %end % %if length(varargin) == 1 & any(varargin{1}(1) == '01234567890+-.') % varargin{1} = eval(varargin{1}); %end % %if length(varargin) == 1 & isequal(class(varargin{1}), 'double') % n = max(round(varargin{1}), 1); % x = rand(n, n); % y = x; % y(y < 0.5) = 0; % y = sparse(y); % z = fix(x * 100); % c = char(z); % xx = x; % yy = y; % zz = z; % cc = c; % filename = [mfilename '_demo.mat']; % disp([' ## Using Mat-file "' filename '".']) % feval(mfilename, filename, 'x', 'y') % feval(mfilename, filename, 'z', 'c', '-append') % clear x y z c % load(filename) % s = [' ## ' mfilename '(' int2str(n) '): Round-trip']; % if isequal(x, xx) & isequal(y, yy) & ... % isequal(z, zz) & isequal(c, cc) % disp([s ' succeeded.']) % else % disp([s ' failed.']) % end % return %end % %% Adjust calling arguments. % %if nargin < 1 % varargin = {'matlab.mat'}; %end % %count = length(varargin); %for i = 1:length(varargin) % var = varargin{i}; % if var(1) == '-' % count = count - 1; % end %end % %if count < 2 % w = evalin('caller', 'whos'); % w = {w.name}; % w = w(:).'; % varargin = [varargin w]; %end % %% Default settings. % %doAppend = 0; %doAsis = 0; %thePrecision = 'float64'; % %% Default M O P T code. % %M = 1; % Machine: IEEE Big-endian. %O = 0; % Always zero. %P = 0; % Precision: see below. %T = 0; % Type of data: matrix (0), string (1), or sparse (2) % %% Interpret the precision and other options. % %for i = 2:length(varargin) % var = varargin{i}; % if var(1) == '-' % switch lower(var) % case {'-double', '-float64'} % thePrecision = 'float64'; % P = 0; % case {'-single', '-float', '-float32'} % thePrecision = 'float32'; % P = 1; % case {'-long', '-slong', '-int32'} % thePrecision = 'int32'; % P = 2; % case {'-short', '-sshort', '-int16'} % thePrecision = 'int16'; % P = 3; % case {'-ushort', '-uint16'} % thePrecision = 'uint16'; % P = 4; % case {'-uchar', '-ubyte', '-uint8'} % thePrecision = 'uint8'; % P = 5; % case '-append' % doAppend = 1; % case '-asis' % doAsis = 1; % otherwise % disp([' ## Unknown thePrecision: ' var]) % return % end % end %end % %% Default to ".mat" extension if none given. % %theFilename = varargin{1}; %if ~any(theFilename == '.') % theFilename = [theFilename '.mat']; %end % %% Open the file in native format. % %if doAppend % fid = fopen(theFilename, 'a', 'native'); %else % fid = fopen(theFilename, 'w', 'native'); %end % %if fid < 0 % disp([' ## ' mfilename ': Unable to open file: ' theFilename]) % return %end % %% Code for machine-format. % %[filename, permission, machineformat] = fopen(fid); %switch machineformat %case 'ieee-le' % M = 0; %case 'ieee-be' % M = 1; %case 'vaxd' % M = 2; %case 'vaxg' % M = 3; %case 'cray' % M = 4; %otherwise % disp([' ## Incompatible machine-format. Nothing saved.']) % fclose(fid) % return %end % %% Save compatible variables. % %for i = 2:length(varargin) % var = varargin{i}; % if var(1) ~= '-' % try % w = evalin('caller', ['which(''' var ''')']); % c = evalin('caller', ['class(' var ')']); % if ~(isequal(w, 'variable') & ... % (isequal(c, 'char') | ... % isequal(c, 'double') | ... % isequal(c, 'sparse'))) % disp(' ') % disp([' ## ' mfilename ': Not a compatible type.']) % disp([' ## Unable to save "' var '".']) % else % x = evalin('caller', var); % sz = size(x); % if length(sz) > 2 % Force to 2-d. % sz = [sz(1) prod(sz(2:end))]; % x = reshape(x, sz); % end % switch class(x) % case 'double' % T = 0; % Type = full-matrix. % prec = thePrecision; % case 'char' % Might be 16-bit Unicode. % T = 1; % Type = string. % P = 4; % Unsigned short integer. % prec = 'uint16'; % As in Matlab v5+. % case 'sparse' % T = 2; % Type = sparse. % prec = thePrecision; % [row, col, val] = find(x); % row = [row(:); sz(1)]; % col = [col(:); sz(2)]; % val = [val(:); 0]; % x = [row col val]; % sz = size(x); % end % if ~doAsis % Pack if all integer. % y = x(:); % if all(isfinite(y)) % if ~isreal(y) % y = [real(y); imag(y)]; % end % if ~any(rem(y, 1)) % mn = min(y); % mx = max(y); % if mn >= 0 & mx < 2^8 % Unsigned byte. % P = 5; % prec = 'uint8'; % elseif mn >= 0 & mx < 2^16 % Unsigned short. % P = 4; % prec = 'uint16'; % elseif mn >= -2^15 & mx < 2^15 % Signed short. % P = 3; % prec = 'int16'; % elseif mn >= -2^31 & mx < 2^31 % Signed long. % P = 2; % prec = 'int32'; % end % end % end % end % MOPT = 1000*M + 100*O + 10*P + T; % mrows = sz(1); % ncols = sz(2); % imagflag = abs(~isreal(x)); % namelen = length(var) + 1; % Includes null-byte. % name = var; % null = 0; % fwrite(fid, [MOPT mrows ncols imagflag namelen], 'uint32'); % fwrite(fid, name, 'uint8'); % fwrite(fid, 0, 'uint8'); % Null-byte. % if imagflag % fwrite(fid, real(x), prec); % fwrite(fid, imag(x), prec); % else % fwrite(fid, x, prec); % end % end % catch % disp(' ') % disp([' ## ' mfilename ': Error = "' lasterr '"']) % disp([' ## Unable to save "' varargin{i} '".']) % end % end %end % %% Close and return. % %fclose(fid); fclose(fout); disp(' ## Installing: "setdef.m" (text)') fout = fopen('setdef.m', 'w'); %function setdef(theFunction) % %% setdef -- Switch to directory of a function. %% setdef(theFunction) switches to the directory %% that contains theFunction. %% setdef (no argument) displays pwd. % %% Copyright (C) 1996 Dr. Charles R. Denham, ZYDECO. %% All Rights Reserved. %% Disclosure without written consent from the %% copyright owner does not constitute publication. % %if nargin > 0 % w = which(theFunction); % f = findstr(w, filesep); % if any(f) % w = w(1:f(length(f))); % eval(['cd(''' w(1:f(length(f))) ''')']) % end %end %disp([' ## ' pwd]) fclose(fout); disp(' ## Installing: "setdir.m" (text)') fout = fopen('setdir.m', 'w'); %function theResult = setdir(theCommand, theTitle, varargin) % %% setdir -- Set directory or get files via dialog. %% setdir (no argument) displays a dialog for selecting the directory %% to be made current, or one or more file names to be returned, %% starting from the present working-directory. Existing directories %% are prefixed by '>' in the file-list. Navigation is accomplished %% through single-clicks on the controls. If a return argument is %% given, the directory will be returned as a string, whereas files %% will be returned in a cell-array of strings. %% setdir([], 'theTitle') sets the dialog name to theTitle. %% %% "Cancel" -- No directory change. %% "Select ..." -- Select the named directory. %% "New" -- Create a new directory. % %% Copyright (C) 1999 Dr. Charles R. Denham, ZYDECO. %% All Rights Reserved. %% Disclosure without explicit written consent from the %% copyright owner does not constitute publication. % %% Version of 30-Dec-1999 10:35:32. %% Updated 19-Oct-2000 11:33:40. % %persistent result %persistent theDirCommand %persistent theFileFilters % %if nargin < 1, theCommand = ''; end %if nargin < 2, theTitle = ''; end % %if isempty(theCommand), theCommand = 'create'; end % %switch lower(theCommand) %case 'closerequestfcn' % result = []; % theDialog = gcbf; % if isempty(theDialog), theDialog = gcf; end % delete(theDialog) % return %case 'callback' % theDialog = gcbf; % if isempty(theDialog), theDialog = gcf; end % switch lower(get(gcbo, 'Tag')) % case 'up' % s = get(gcbo, 'String'); % v = get(gcbo, 'Value'); % for i = v+1:length(s) % cd .. % end % feval(mfilename, 'update') % case 'down' % s = get(gcbo, 'String'); % v = get(gcbo, 'Value'); % f = findobj(theDialog, 'Tag', 'okay'); % x = ''; % if any(v), x = s{v(1)}; end % if isequal(x, '..') % try, cd .., catch, disp(' ## Already at top-level.'), end % feval(mfilename, 'update') % elseif any(x) & isequal(x(1), '>') % cd(x(2:end)) % feval(mfilename, 'update') % else % s = 'Select File'; % if isempty(v) % s = 'None Selected'; % elseif length(v) < 2 % s = 'Select File'; % elseif length(v) > 1 % s = 'Select Files'; % end % set(f, 'String', s); % end % case 'cancel' % result = []; % delete(theDialog) % case 'new' % try % set(theDialog, 'WindowStyle', 'normal') % s.NewFolderName = 'untitled folder'; % isModal = ~any(findstr(computer, 'pcwin')); % s = guido(s, 'New Folder', isModal); % set(theDialog, 'WindowStyle', 'modal') % if ~isempty(s) % try % mkdir(s.NewFolderName) % cd(s.NewFolderName) % catch % disp(lasterr) % end % end % catch % end % feval(mfilename, 'update') % return % case 'okay' % f = findobj(theDialog, 'Tag', 'down'); % s = get(f, 'String'); % v = get(f, 'Value'); % if any(v) & v(1) > 1 % result = s(v); % for i = 1:length(result) % result{i} = which(result{i}); % end % else % f = findobj(theDialog, 'Tag', 'up'); % s = get(f, 'String'); % result = pwd; % end % delete(theDialog) % otherwise % end % return %case 'keypressfcn' % theDialog = gcbf; % if isempty(theDialog), theDialog = gcf; end % theKey = lower(get(theDialog, 'CurrentCharacter')); % if lower(theKey) >= 'a' & lower(theKey) < 'z' % h = findobj(theDialog, 'Type', 'uicontrol', 'Tag', 'down'); % s = get(h, 'String'); % theIndex = 0; % for i = 1:length(s) % theName = lower(s{i}); % if theName(1) == '>', theName(1) = ''; end % if theName(1) > theKey % break % elseif theName(1) < theKey % theIndex = i; % else % theIndex = i; % break % end % end % if any(theIndex) % set(h, 'Value', theIndex, 'ListBoxTop', theIndex) % end % end % return %case 'update' % if isempty(theFileFilters) % d = feval(theDirCommand); % else % d = feval(theDirCommand, theFileFilters{:}); % end % s = {'..'}; % theIndex = []; % for i = 1:length(d) % theName = d(i).name; % if d(i).isdir % theName = ['>' theName]; % end % s{end+1} = theName; % end % if isempty(s), s = {'(folder is empty)'}; end % if isempty(theIndex), theIndex = 1; end % p = pwd; % if p(1) ~= filesep, p = [filesep p]; end % if p(end) ~= filesep, p(end+1) = filesep; end % index = find(p == filesep); % t = []; % for i = 1:length(index)-1 % t{i} = p(index(i)+1:index(i+1)-1); % end % theDialog = gcbf; % if isempty(theDialog), theDialog = gcf; end % h = findobj(theDialog, 'Type', 'uicontrol', 'Tag', 'up'); % set(h, 'String', t , 'Value', length(t)) % h = findobj(theDialog, 'Type', 'uicontrol', 'Tag', 'down'); % set(h, 'String', s, 'Value', theIndex) % h = findobj(theDialog, 'Type', 'uicontrol', 'Tag', 'okay'); % set(h, 'String', ['Select ' t{end}]) % return %case 'create' % theDirCommand = 'dir'; % if exist('dirsafe.m', 'file') % theDirCommand = 'dirsafe'; % end % theFileFilters = varargin; % theOldPWD = pwd; % if isempty(theTitle), theTitle = 'Set Directory'; end % theFigure = figure( ... % 'Name', theTitle, ... % 'NumberTitle', 'off', ... % 'WindowStyle', 'modal', ... % 'CloseRequestFcn', [mfilename ' CloseRequestFcn'], ... % 'KeyPressFcn', [mfilename ' KeyPressFcn'] ... % ); % width = 300; % height = 200; % pos = get(theFigure, 'Position'); % pos(1) = pos(1) + 100; % pos(2) = pos(2)+pos(4)-height - 100; % pos(3) = width; % pos(4) = height; % set(theFigure, 'Position', pos) % h = []; % h(end+1) = uicontrol(theFigure, ... % 'Style', 'popupmenu', ... % 'String', {'-'}, ... % 'Value', 1, ... % 'Tag', 'up'); % h(end+1) = uicontrol(theFigure, ... % 'Style', 'listbox', ... % 'FontSize', 12', ... % 'FontWeight', 'bold', ... % 'String', {'-'}, ...' % 'Value', 1, ... % 'Min', 1, ... % 'Max', 1e6, ... % Multiple selection. % 'Tag', 'down'); % h(end+1) = uicontrol(theFigure, ... % 'Style', 'pushbutton', ... % 'String', 'Cancel', ... % 'BackgroundColor', [10 5 5]/10, ... % 'Tag', 'cancel'); % h(end+1) = uicontrol(theFigure, ... % 'Style', 'pushbutton', ... % 'String', 'Okay', ... % 'BackgroundColor', [5 10 5]/10, ... % 'Tag', 'okay'); % h(end+1) = uicontrol(theFigure, ... % 'Style', 'pushbutton', ... % 'String', 'New Dir', ... % 'BackgroundColor', [5 5 10]/10, ... % 'Tag', 'new'); % % % theFontName = get(0, 'DefaultUIControlFontName'); % theFontSize = 12; % theFontWeight = 'bold'; % % set(h, ... % 'FontName', theFontName, ... % 'FontSize', theFontSize, ... % 'FontWeight', theFontWeight, ... % 'Callback', [mfilename ' Callback']) % % x = inf; % % theLayout = [ % x x x 1 1 1 1 1 x x x % 2 2 2 2 2 2 2 2 2 2 2 % 2 2 2 2 2 2 2 2 2 2 2 % 2 2 2 2 2 2 2 2 2 2 2 % 2 2 2 2 2 2 2 2 2 2 2 % 2 2 2 2 2 2 2 2 2 2 2 % 3 3 3 4 4 4 4 4 5 5 5 % ]; % % uilayout(h, theLayout) % % feval(mfilename, 'update') % % waitfor(theFigure) % % if isempty(result), cd(theOldPWD); end % if nargout > 0 % theResult = result; % else % disp(result) % end % return %otherwise % disp(theCommand) % return %end % % %% ---------- uilayout ---------- % % % %function theResult = uilayout(theControls, theLayout, thePosition) % %% uilayout -- Layout for ui controls. %% uilayout(theControls, theLayout) positions theControls %% according to theLayout, an array whose entries, taken %% in sorted order, define the rectangular extents occupied %% by each control. TheLayout defaults to a simple vertical %% arrangement of theControls. A one-percent margin is %% imposed between controls. To define a layout region %% containing no control, use Inf. %% uilayout(..., thePosition) confines the controls to the %% given normalized position of the figure. This syntax %% is useful for embedding controls within a frame. %% uilayout (no argument) demonstrates itself. % %% Copyright (C) 1997 Dr. Charles R. Denham, ZYDECO. %% All Rights Reserved. %% Disclosure without explicit written consent from the %% copyright owner does not constitute publication. % %% Version of 18-Apr-1997 08:07:54. % %if nargin < 1, theControls = 'demo'; help(mfilename), end % %if strcmp(theControls, 'demo') % theLayout = [1 2; % 3 4; % 5 Inf; % 5 6; % 5 Inf; % 7 8; % 9 10; % 11 12; % 13 14]; % [m, n] = size(theLayout); % thePos = get(0, 'DefaultUIControlPosition'); % theSize = [n+2 m+2] .* thePos(3:4); % theFigure = figure('Name', 'UILayout', ... % 'NumberTitle', 'off', ... % 'Resize', 'off', ... % 'Units', 'pixels'); % thePos = get(theFigure, 'Position'); % theTop = thePos(2) + thePos(4); % thePos = thePos .* [1 1 0 0] + [0 0 theSize]; % thePos(2) = theTop - (thePos(2) + thePos(4)); % set(theFigure, 'Position', thePos); % theFrame = uicontrol('Style', 'frame', ... % 'Units', 'normalized', ... % 'Position', [0 0 1 1], ... % 'BackgroundColor', [0.5 1 1]); % theStyles = {'checkbox'; 'text'; ... % 'edit'; 'text'; ... % 'listbox'; 'text'; ... % 'popupmenu'; 'text'; ... % 'pushbutton'; 'text'; ... % 'radiobutton'; 'text'; ... % 'text'; 'text'}; % theStrings = {'Anchovies?', '<-- CheckBox --', ... % 'Hello World!', '<-- Edit --', ... % {'Now', 'Is', 'The' 'Time' 'For' 'All' 'Good', ... % 'Men', 'To', 'Come' 'To' 'The' 'Aid' 'Of', ... % 'Their' 'Country'}, ... % '<-- ListBox --', ... % {'Cheetah', 'Leopard', 'Lion', 'Tiger', 'Wildcat'}, ... % '<-- PopupMenu --', ... % 'Okay', '<-- PushButton --', ... % 'Cream?', '<-- RadioButton --', ... % 'UILayout', '<-- Text --'}; % theControls = zeros(size(theStyles)); % for i = 1:length(theStyles) % theControls(i) = uicontrol('Style', theStyles{i}, ... % 'String', theStrings{i}, ... % 'Callback', ... % 'disp(int2str(get(gcbo, ''Value'')))'); % end % set(theControls(1:2:length(theControls)), 'BackGroundColor', [1 1 0.5]) % set(theControls(2:2:length(theControls)), 'BackGroundColor', [0.5 1 1]) % thePosition = [1 1 98 98] ./ 100; % uilayout(theControls, theLayout, thePosition) % set(theFrame, 'UserData', theControls) % theStyles, theLayout, thePosition % if nargout > 0, theResult = theFrame; end % return %end % %if nargin < 2, theLayout = (1:length(theControls)).'; end %if nargin < 3, thePosition = [0 0 1 1]; end % %a = theLayout(:); %a = a(finite(a)); %a = sort(a); %a(diff(a) == 0) = []; % %b = zeros(size(theLayout)); % %for k = 1:length(a) % b(theLayout == a(k)) = k; %end % %[m, n] = size(theLayout); % %set(theControls, 'Units', 'Normalized') %theMargin = [1 1 -2 -2] ./ 100; %for k = 1:min(length(theControls), length(a)) % [i, j] = find(b == k); % xmin = (min(j) - 1) ./ n; % xmax = max(j) ./ n; % ymin = 1 - max(i) ./ m; % ymax = 1 - (min(i) - 1) ./ m; % thePos = [xmin ymin (xmax-xmin) (ymax-ymin)] + theMargin; %if (1) % thePos = thePos .* thePosition([3 4 3 4]); % thePos(1:2) = thePos(1:2) + thePosition(1:2); %end % set(theControls(k), 'Position', thePos); %end % %if nargout > 0, theResult = theControls; end % % %% ---------- dirsafe ---------- % % % %function theResult = dirsafe(varargin) % %% dirsafe -- Directory listing for multiple file filters. %% dirsafe('filt1', 'filt2') returns the alphabetized "dir" %% listing for all the given file-filters. The default %% is '*'. % %% Copyright (C) 2000 Dr. Charles R. Denham, ZYDECO. %% All Rights Reserved. %% Disclosure without explicit written consent from the %% copyright owner does not constitute publication. % %% Version of 16-Oct-2000 14:07:45. %% Updated 19-Oct-2000 11:25:40. % %if nargin < 1, varargin = {'*'}; end %if nargin == 1 % if ~iscell(varargin{1}), varargin{1} = {varargin{1}}; end %end % %filters = varargin; % %% Gather the subdirectories. % %files = dir; %for i = length(files):-1:1 % if ~files(i).isdir % files(i) = []; % end %end % %% Gather files for all the filters. % %for i = 1:length(filters) % files = [files; dir(filters{i})]; %end % %% Sort by name. % %[s, indices] = sort({files.name}); % %files = files(indices); % %% Remove duplicates. % %for i = length(files):-1:2 % if isequal(files(i), files(i-1)) % files(i) = []; % s(i) = []; % end %end % %% Interleave upper and lower case. % %f = {files.name}; %for i = 1:length(f) % f{i} = lower(f{i}); %end %[f, indices] = sort(f); %files = files(indices); %s = s(indices); % %if nargout > 0 % theResult = files; %else % disp(s) %end fclose(fout); disp(' ## Installing: "setinfo.m" (text)') fout = fopen('setinfo.m', 'w'); %function [theResult, isOkay] = setinfo(theInfo, theField, theValue) % %% setinfo -- Set field value in an "Info" struct. %% setinfo(theInfo, 'theField', theValue) updates %% 'theField' to theValue in theInfo, a struct %% that is compatible with the "uigetinfo" function. %% If 'theField' does not exist, it will be created %% to receive theValue. %% [theResult, isOkay] = ... returns isOkay = 0 %% if an error occurred; otherwise, non-zero. %% setinfo(theInfo, 'theField') invokes "getinfo". %% setinfo(theInfo) adjusts theInfo to canonical %% form. % %% Copyright (C) 1997 Dr. Charles R. Denham, ZYDECO. %% All Rights Reserved. %% Disclosure without explicit written consent from the %% copyright owner does not constitute publication. % %% Version of 07-Feb-1998 09:45:56. %% Updated 14-Nov-2001 15:21:24. % %if nargout > 0, theResult = []; end %if nargin < 1, help(mfilename), return, end % %% Put all fields into canonical form. % %if nargin < 2 % result = theInfo; % theFields = fieldnames(result); % isOkay = 1; % for i = 1:length(theFields) % theValue = getfield(result, theFields{i}); % switch class(theValue) % case 'struct' % [res, okay] = setinfo(theValue); % isOkay = isOkay & okay; % result = setfield(result, theFields{i}, res); % case 'cell' % if length(theValue) == 1 & ... % (isequal(theValue{1}, 'radiobutton') | ... % isequal(theValue{1}, 'checkbox')) % theValue{2} = 0; % result = setfield(result, theFields{i}, theValue); % elseif length(theValue) == 1 & iscell(theValue{1}) % theValue{2} = 1; % result = setfield(result, theFields{i}, theValue); % elseif ~isequal(theValue{1}, 'radiobutton') & ... % ~isequal(theValue{1}, 'checkbox') % theValue{1} = {theValue{1}}; % theValue{2} = 1; % else % theValue; % end % otherwise % end % end % if nargout > 0, theResult = result; end % return %end % %[theVal, isOkay] = getinfo(theInfo, theField); % %if nargin == 2 % if nargout > 0 % theResult = theVal; % else % disp(theVal) % end % return %end % %if ischar(theField) & any(theField == '.') % theField = [theField '.']; % f = find(theField == '.'); % theParts = cell(1, length(f)); % k = 0; % for i = 1:length(f) % theParts{i} = theField(k+1:f(i)-1); % k = f(i); % end % theField = theParts; %elseif ~iscell(theField) % theField = {theField}; %end % %result = theInfo; % %if ~all(isOkay) % Create a new field. % isOkay = 1; %% eval('result = setfield(theInfo, theField, theValue);', 'isOkay = 0;'); % eval('result = setfield(theInfo, theField{:}, theValue);', 'isOkay = 0;'); %else % Update an existing field. % isokay = 1; %% eval('theVal = getfield(theInfo, theField);', 'isOkay = 0;'); % eval('theVal = getfield(theInfo, theField{:});', 'isOkay = 0;'); % if ~isOkay, theVal = []; end % switch class(theVal) % case 'cell' % if isequal(theVal{1}, 'checkbox') | isequal(theVal{1}, 'radiobutton') % % Do nothing. % elseif ~iscell(theVal{1}) % theVal{1} = {theVal{1}}; % theVal{2} = 1; % end % end % switch class(theVal) % case 'cell' % if isequal(theVal{1}, 'checkbox') | isequal(theVal{1}, 'radiobutton') % theVal{2} = any(any(theValue)); % else % switch class(theValue) % case 'double' % if theValue > 0 & theValue <= length(theVal{1}) % theVal{2} = theValue; % end % otherwise % flag = 0; % for i = 1:length(theVal{1}) % if isequal(theVal{1}{i}, theValue) % theVal{2} = i; % flag = 1 % end % end % if ~any(flag) % Append. % theVal{1} = [theVal(:); {theValue}]; % theVal{2} = length(theVal{1}); % end % end %% else %% theVal{1} = [{theValue}; theVal(:)]; % end % otherwise % theVal = theValue; % end % isOkay = 1; %% eval('result = setfield(theInfo, theField, theVal);', 'isOkay = 0;'); % eval('result = setfield(theInfo, theField{:}, theVal);', 'isOkay = 0;'); %end % %if nargout > 0 % theResult = result; %else % disp(result) %end fclose(fout); disp(' ## Installing: "setsafe.m" (text)') fout = fopen('setsafe.m', 'w'); %function theResult = setsafe(varargin) % %% setsafe -- Fault-tolerant and non-redundant "set". %% setsafe('demo') demonstrates itself. %% setsafe(theHandle, ...) sets only those properties %% that would actually change. The argument-list %% consists of a valid handle, followed by name/value %% pairs, followed by another handle, etc., so long %% as the list makes sense. In the case of multiple %% handles, each block is set before processing the next, %% as if several "set" calls were executed in sequence. %% The result is logically true if some values were set %% successfully; otherwise, it is false. %% %% Note: this routine overcomes the propensity of Matlab %% to generate redundant screen-updates under X-Windows. % %% Copyright (C) 2000 Dr. Charles R. Denham, ZYDECO. %% All Rights Reserved. %% Disclosure without explicit written consent from the %% copyright owner does not constitute publication. % %% Version of 11-Feb-2000 11:56:50. %% Updated 11-Feb-2000 17:02:36. % %global SETSAFE_VERBOSE % %if nargout > 0, theResult = 1; end %if nargin < 1, help(mfilename), varargin = {'demo'}; end % %if isempty(SETSAFE_VERBOSE), SETSAFE_VERBOSE = ~~0; end % %if isequal(varargin{1}, 'demo') % SETSAFE_VERBOSE = ~~1; % disp([' >> ' mfilename ' demo']), disp(' ') % c{1} = 'setsafe(gcf, ''Name'', [mfilename '' demo''])'; % c{2} = 'setsafe(gcf, ''Color'', [1 0 0], ''Color'', [0 0 1])'; % disp([' >> ' c{1}]) % disp([' >> ' c{2}]) % eval(c{1}) % eval(c{2}) % SETSAFE_VERBOSE = ~~0; % return %end % %vargs = {}; %mode = 'handle'; %i = 0; % Index of arguments already processed. % %while i <= length(varargin) % if i >= length(varargin) % mode = 'set'; % else % v = varargin{i+1}; % end % switch mode % case 'handle' % Looking for a handle. % if ishandle(v) % if SETSAFE_VERBOSE, disp([' ## ' mode ' ' mat2str(v)]), end % vargs = {v}; % mode = 'property'; % i = i+1; % else % mode = 'ignore'; % end % case 'property' % Looking for a property-name. % if ischar(v) % if SETSAFE_VERBOSE, disp([' ## ' mode ' ''' mat2str(v) '''']), end % vargs{end+1} = v; % mode = 'value'; % i = i+1; % elseif ishandle(v) % mode = 'set'; % else % mode = 'ignore'; % end % case 'value' % Looking for a property-value. % if SETSAFE_VERBOSE % theClass = class(v); % switch theClass % case 'double' % disp([' ## ' mode ' ' mat2str(v)]) % case 'char' % disp([' ## ' mode ' ''' mat2str(v) '''']) % otherwise % disp([' ## ' mode]) % disp(v) % end % end % vargs{end+1} = v; % mode = 'property'; % i = i+1; % case 'set' % if SETSAFE_VERBOSE, disp([' ## ' mode]), end % if nargout > 0 % theResult = nrset(vargs{:}); % else % nrset(vargs{:}); % end % if i == length(varargin), break; end % vargs = {}; % mode = 'handle'; % case 'ignore' % i = i+1; % mode = 'set'; % end % if i >= length(varargin) % mode = 'set'; % end %end % %% ---------- nrset ---------- % % %function theResult = nrset(varargin) % %% nrset -- Non-redundant "set". %% nrset(theHandle, ...) performs non-redundant "set", %% which attempts to set only those properties that %% would actually change. All of the requested %% properties are checked before any of them are set. %% The result is logically true if any values were %% set successfully; otherwise, it is false. % %% Copyright (C) 2000 Dr. Charles R. Denham, ZYDECO. %% All Rights Reserved. %% Disclosure without explicit written consent from the %% copyright owner does not constitute publication. % %% Version of 11-Feb-2000 12:57:27. %% Updated 20-Apr-2000 15:23:10. % %global SETSAFE_VERBOSE % %if nargout > 0, theResult = 0; end %if nargin < 1, help(mfilename), return, end % %if length(varargin) < 1, return, end % %theHandle = varargin{1}; % %k = length(varargin); %if rem(k, 2), k = k-1; end % %while k > 1 % theName = varargin{k}; % if k < length(varargin) % theValue = varargin{k+1}; % try % redundant = ~~1; % for i = 1:length(theHandle) % x = get(theHandle(1), theName); % if ~isequal(x, theValue) % redundant = ~~0; % break % end % end % if redundant % if any(SETSAFE_VERBOSE) % disp([' ## redundant property ''' theName '''']) % end % varargin(k:k+1) = []; % end % catch % disp([' ## ' mfilename ': ' lasterr]) % return % end % end % k = k-2; %end % %okay = (nargin > 1 & length(varargin) > 1) | ... % (nargin == 1 & length(varargin) == 1); % %if okay % try % if nargout > 0 % theResult = set(varargin{:}); % else % set(varargin{:}); % end % theResult = 1; % catch % disp([' ## ' mfilename ': ' lasterr]) % end %end fclose(fout); disp(' ## Installing: "sliceg.m" (text)') fout = fopen('sliceg.m', 'w'); %function zi = sliceg(x, y, z, xi, yi, method) % %% sliceg -- Interpolation along a non-monotonic track. %% sliceg('demo') demonstrates itself. %% sliceg(N) demonstrates itself with an N-by-N surface %% and N points along a random track (default = 10). %% sliceg(x, y, z, xi, yi, 'method') uses the syntax of %% "interp2" to interpolate the (x, y, z) grid along %% a (possibly) non-monotonic (xi, yi) track. The %% track points must be unique. When z is three- %% dimensional, the result bears one row for each %% layer, representing the volumetric slice. %% %% Also see: "help interp2". % %% Copyright (C) 2000 Dr. Charles R. Denham, ZYDECO. %% All Rights Reserved. %% Disclosure without explicit written consent from the %% copyright owner does not constitute publication. % %% Version of 20-Jan-2000 12:17:03. %% Updated 20-Apr-2000 16:26:52. % %% Note: This routine needs to be enhanced to process %% a non-plaid grid. INTERP2 only works with plain. %% The easiest way would be to locate the indices %% of the (xi, yi) points within the (x, y) grid, %% then compute zi by index. % %if nargin < 1, x = 'demo'; help(mfilename), end % %if isequal(x, 'demo'), x = 10; end % %if ischar(x), x = eval(x); end % %if length(x) < 2 % n = x; % i = linspace(0, 1, n+1); % [x, y] = meshgrid(i, i); % z = x + y; % xi = sort(rand(1, n)); % yi = rand(size(xi)); % result = feval(mfilename, x, y, z, xi, yi); % surf(x, y, z); % hold on % plot3(xi, yi, 0*result-1, '-g', 'LineWidth', 3); % plot3(xi, yi, 0*result+3, '-g', 'LineWidth', 3); % plot3([xi;xi], [yi; yi], [0*result-1; 0*result+3], '-ko') % plot3(xi, yi, result+0.01, '-k', 'LineWidth', 3); % hold off % box on % shading faceted % rotate3d % figure(gcf) % s = [mfilename ' ' int2str(n)]; % set(gcf, 'Name', s) % return %end % %% Sort the data and remember original indices. %% We assume that there are no points identical. % %[yi, indx] = sort(yi); %xi = xi(indx); %[xi, jndx] = sort(xi); %yi = yi(jndx); %indx = indx(jndx); % %sz = size(z); %if length(sz) == 2, sz = [sz 1]; end % %z = reshape(z, sz); % %nLayers = size(z, 3); % %xi = xi(:).'; yi = yi(:).'; %zi = zeros(nLayers, length(xi)); % %if nargin < 6 % for k = 1:nLayers % temp = interp2(x, y, z(:, :, k), xi, yi); % zi(k, :) = temp(:).'; % end %else % for k = 1:nlayers % temp = interp2(x, y, z(:, :, k), xi, yi, method); % zi(k, :) = temp(:).'; % end %end % %zi(:, indx) = zi; fclose(fout); disp(' ## Installing: "snackbar_bundle.m" (text)') fout = fopen('snackbar_bundle.m', 'w'); %function snackbar_bundle % %% snackbar_bundle -- Bundle "Matlab Snackbar" m-files. % %% Copyright (C) 2000 Dr. Charles R. Denham, ZYDECO. %% All Rights Reserved. %% Disclosure without explicit written consent from the %% copyright owner does not constitute publication. % %% Version of 14-Feb-2000 16:44:08. %% Updated 30-Apr-2003 11:21:49. % %ELAPSED = 'disp(['' ## Elapsed time: '' int2str(toc) '' s'']) % Timing.'; % %tic % %% Find the "end.m" routine. % %p = pwd; %utility %end_m = which('end.m'); %cd(p) % %theMFiles = { % mfilename % % end_m % % 'fixnl.m' % % 'tri_install' % % 'polyfitn' % new 30-Apr-2003 11:28:49. % 'polyvaln' % new 30-Apr-2003 11:28:49. % % 'hello' % % 'basic_english' % new 03/08/2002. % 'll' % new 03/08/2002. % 'lsd' % new 03/08/2002. % 'uidefaults' % new 03/08/2002. % % 'nanequal' % new 20-Mar-2002 % 'nanzero' % new 20-Mar-2002 % 'allequal' % new 20-Mar-2002 % 'anyequal' % new 20-Mar-2002 % % 'ezgrid' % new 02-Apr-2002 . % 'tmpname' % new 02-Apr-2002 . % % 'bringtofront' % % 'filepick_install' % % 'subplotsafe' % % 'numel' % % 'dirinfo' % 'deg2dms' % 'identical' % 'mailto' % % 'mst' % minimal spanning tree. % % 'ydrag' % new 05Dec2001. % % 'save4' % new 18Jan2002. % % 'genetic' % % 'qsum1' % 'tensor_mul' % 'tensor_sol' % 'tensor_test' % 'xabx' % % 'again' % 'suspend' % % 'crossings' % % 'describe' % 'inherit' % 'super' % % 'dateaxis' % 'dhms' % 'datenum2julian' % 'julian2datenum' % 'yearday' % % 'setdef' % 'setdir' % 'fcomment' % % 'fcat' % % 'insidesafe' % 'tsearchsafe' % % 'fig2jpeg' % 'findstr1' % 'fsearch' % 'loadsafe' % 'fps' % 'fpt' % 'rect' % 'rect2grid' % 'findobjs' % 'guido' % 'getinfo' % 'setinfo' % 'hint' % 'uilayout' % 'sliceg' % 'geo_simplify' % 'xy_simplify' % 'ascii' % 'assign' % 'beep' % 'begets' % 'demonstrate' % 'int2english' % 'snowfall' % 'spar' % 'unspar' % 'swap' % 'throw' % 'undoc' % 'whov' % 'blinksafe' % 'marksafe' % 'busy' % 'idle' % 'doubleclick' % 'findpt' % 'rbrect' % 'zoomsafe' % 'movie1' % 'parts' % 'partnames' % 'arrowsafe' % 'bgtext' % 'label1' % 'label2' % 'labelsafe' % 'nofigs' % 'plot1' % 'plot2' % 'vargstr' % 'sortplot' % 'stackplot' % 'starsafe' % 'symbsafe' % 'wigglex' % 'wiggley' % 'fpeval' % 'uidelete' % % 'getsafe' % 'setsafe' % % 'at' % 'vi' % % 'which1s' % 'calls' % 'frot13' % 'gridterp' % 'terp4' % % 'lineno' % }; % %theMessage = { % ' ' % ' ## Add "snackbar" to your Matlab path.' % ' ## Then restart Matlab.' %}; % %theMFiles = sort(theMFiles); % %for i = length(theMFiles):-1:2 % if isequal(theMFiles{i}, theMFiles{i-1}) % theMFiles(i) = []; % end %end % %setdef(mfilename) % %fclose('all'); % %okay = 1; %for i = 1:length(theMFiles) % w = which(theMFiles{i}); % if ~any(w) % disp([' ## Not found: ' theMFiles{i}]) % okay = 0; % end %end % %if ~okay % disp(' ## Some M-files not found.') % return %end % %if (0) % dst_name = 'snackbar_install'; % dir_name = 'snackbar'; % % delete([dst_name '.m']) % delete([dst_name '.p']) % % self = bundle(dst_name, 'new'); % disp(' '), disp(self) % self = add_checkdir(self, dir_name); % self = add_setdir(self, dir_name); % % self = add_mfile(self, theMFiles); % % self = add_binary(self, 'fixnl.p'); % % self = add_setdir(self, '..'); % % self = add_message(self, theMessage); % % self = make_pcode(self); % % eval(ELAPSED) % %end % %% The new bundler system: % %at(mfilename) % %bund new snackbar %bund setdir snackbar %bund('mfile', theMFiles) %bund cd .. %bund('disp', theMessage) %bund close fclose(fout); disp(' ## Installing: "snowfall.m" (text)') fout = fopen('snowfall.m', 'w'); %function [year, day] = snowfall % %% snowfall -- First snowfall, Logan Airport, Boston, MA. %% [year, day] = snowfall (no argument) returns or displays %% he year and the day of then first trace of snow after %% September 30, beginning with 1891. %% Source: Boston Sunday Globe, December 26, 1999, %% page B8, based on National Weather Service data. %% The values were taken from the graph using a %% Gerber scale. %% yd = snowfall (no argument) returns the snowfall data %% as a two-column array [year day]. % %% Copyright (C) 1999 Dr. Charles R. Denham, ZYDECO. %% All Rights Reserved. %% Disclosure without explicit written consent from the %% copyright owner does not constitute publication. % %% Version of 29-Dec-1999 09:15:01. %% Updated 13-Jan-2000 09:19:13. % %data = [ % Day and year. %23 1891 %35 1892 %46 1893 %37 1894 %52 1895 %44 1896 %43 1897 %56 1898 % 3 1899 %40 1900 %64 1901 %29 1902 %63 1903 %27 1904 %44 1905 %52 1906 %62 1907 %44 1908 %26 1909 %44 1910 %33 1911 %43 1912 %14 1913 %27 1914 %46 1915 %43 1916 %24 1917 %57 1918 %36 1919 %46 1920 %38 1921 %55 1922 %39 1923 %48 1924 %10 1925 %36 1926 %58 1927 %27 1928 %52 1929 %48 1930 %37 1931 %50 1932 %37 1933 %13 1934 %46 1935 %47 1936 %50 1937 %47 1938 %40 1939 %21 1940 %24 1941 %34 1942 %42 1943 %37 1944 %35 1945 %46 1946 %43 1947 %60 1948 %38 1949 %52 1950 %32 1951 %30 1952 %37 1953 %56 1954 %47 1955 %42 1956 %26 1957 %60 1958 %39 1959 %24 1960 %15 1961 %25 1962 %31 1963 %21 1964 %32 1965 %63 1966 %38 1967 %41 1968 %22 1969 %17 1970 %41 1971 %15 1972 %77 1973 %62 1974 %31 1975 %41 1976 %44 1977 %52 1978 %10 1979 %41 1980 %58 1981 %45 1982 %45 1983 %44 1984 %47 1985 %42 1986 %41 1987 % 8 1988 %49 1989 %39 1990 %39 1991 %39 1992 %55 1993 %54 1994 %44 1995 %58 1996 %45 1997 %83 1998 %105 1999 % And still counting. %]; % %yr = data(:, 2); %da = data(:, 1); % %if nargout > 0 % year = yr; % day = da; % if nargout < 2 % year = [yr da]; % else % year = yr; % day = da; % end %else % help(mfilename) % x = yr; % y = da; % xi = yr; % p1 = polyfit(x, y, 1); % p2 = polyfit(x, y, 2); % p3 = polyfit(x, y, 3); % y1 = polyval(p1, xi); % y2 = polyval(p2, xi); % y3 = polyval(p3, xi); % subplot(2, 1, 1) % if exist('hilbert', 'file') == 2 % h = feval('hilbert', y - mean(y)); % hi = abs(h) + mean(y); % lo = -abs(h) + mean(y); % plot(x, y, '-bo',x(end), y(end), 'r*', x, hi, 'k-', x, lo, 'k-') % else % plot(x, y, '-bo',x(end), y(end), 'r*') % end % axis tight % title('First Trace of Snow at Logan Airport') % xlabel('Year') % ylabel('Days After September 30') % subplot(2, 1, 2) % plot(x, y, 'o',x(end), y(end), 'r*', xi, y1, xi, y2, xi, y3) % axis tight % xlabel('Year') % ylabel('Days After September 30') % zoomsafe all % findpt % figure(gcf) % legend('data', '1999', '1st order', '2nd', '3rd', 0) % set(gcf, 'Name', 'SnowFall', 'ResizeFcn', 'legend') %end fclose(fout); disp(' ## Installing: "sortplot.m" (text)') fout = fopen('sortplot.m', 'w'); %function theResult = sortplot(x, y, theBinSize, varargin) % %% sortplot -- Plot sorted chunks. %% sortplot(x, y, theBinSize, varargin) plots y(x), but %% with y first sorted into bins of theChunkSize (default %% is one-tenth the length of x). Any additional arguments, %% such as line-type, are passed intact to "plot". %% sortplot(nData, binSize) demonstrates itself for nData, %% using the binSize. nData defaults to 1000; binSize to %% one-tenth of nData. %% sortplot('demo') demonstrates itself. %% sortplot (no argument) demonstrates itself. % %% Copyright (C) 1997 Dr. Charles R. Denham, ZYDECO. %% All Rights Reserved. %% Disclosure without explicit written consent from the %% copyright owner does not constitute publication. % %% Version of 14-May-1998 16:28:43. %% Updated 18-Oct-1999 09:55:49. % %if nargin < 1 | isequal(x, 'demo'), x = 1000; end % %if nargin > 0 & ischar(x) & ~isequal(x, 'demo') % x = eval(x); %end %if nargin > 1 & ischar(y) % y = eval(y); %end % %if length(x) == 1 % help(mfilename) % n = x; % c = round(n./10); % if nargin > 1, c = y(1); end % x = 1:n; % y = randn(1, n); % subplot(2, 1, 1) % plot(x, y) % xlabel('X'), ylabel('Y') % title(['Y = RandN( 1, ' int2str(n) ' )']) % subplot(2, 1, 2) % sortplot(x, y, c) % xlabel('X'), ylabel('Sorted Y') % title(['SortPlot( Y, ', int2str(c) ' )']) % set(gcf, 'Name', 'SortPlot Demo') % figure(gcf) % zoomsafe all, findpt % return %end % %if nargin < 2 % y = x(:); % x = 1:length(y); % theBinSize = ceil(length(x) ./ 10); % varargin = {}; %elseif nargin < 3 % if ischar(y) % varargin = {y}; % y = x(:); % x = 1:length(y); % theBinSize = ceil(length(x) ./ 10); % elseif length(y) == 1 % theBinSize = y; % y = x(:); % x = 1:length(y); % else % theBinSize = ceil(length(x) ./ 10); % varargin = {}; % end %elseif ischar(theBinSize) % varargin = [varargin {theBinSize}]; % theBinSize = upper(length(x) ./ 10); %end % %x = x(:); %y = y(:); % %[m, n] = size(x); % %width = ceil((length(y)) ./ theBinSize); %u = zeros(theBinSize, width) + NaN; % %u(1:length(y)) = y; % %s = sort(u); %s = s(:); %s = s(1:length(y)); % %result = plot(x, s, varargin{:}); % %if nargout > 0, theResult = result; end fclose(fout); disp(' ## Installing: "spar.m" (text)') fout = fopen('spar.m', 'w'); %function y = spar(x, realFlag) % %% spar -- Convert array to "spar" form. %% spar(x) returns a matrix whose rows list the indices %% and complex values of the non-zero elements of array x. %% The real and imaginary components are placed in separate %% columns. Trailing rows or columns of zeros are ignored. %% See "help unspar" for the inverse conversion. %% spar(x, realFlag) delivers only the real-component of x, %% if realFlag is TRUE; no column for the imaginary-component %% is returned. % %% Copyright (C) 1999 Dr. Charles R. Denham, ZYDECO. %% All Rights Reserved. %% Disclosure without explicit written consent from the %% copyright owner does not constitute publication. % %% Version of 19-Aug-1999 14:10:59. %% Updated 24-Aug-1999 11:34:47. % %if nargout > 0, y = []; end %if nargin < 1, help(mfilename), return, end %if nargin < 2, realFlag = 0; end % %siz = size(x); %dim = length(siz); % %ind = find(x); % %sub = cell(1, dim); %[sub{:}] = ind2sub(siz, ind); % %if ~realFlag % result = zeros(length(ind), dim+2); %else % result = zeros(length(ind), dim+1); %end % %for j = 1:dim % result(:, j) = sub{j}; %end % %if ~realFlag % result(:, end-1) = real(x(ind)); % result(:, end) = imag(x(ind)); %else % result(:, end) = real(x(ind)); %end % %if nargout > 0 % y = result; %else % disp(result) % assignin('caller', 'ans', result) %end fclose(fout); disp(' ## Installing: "stackplot.m" (text)') fout = fopen('stackplot.m', 'w'); %function h = StackPlot(varargin) % %% StackPlot -- Plot of stacked curves. %% StackPlot(x, y, 'theColor', ...) plots the columns %% of y(x) adjacent to each other, with a small margin. %% The syntax is exactly the same as for "plot()". The %% "UserData" property of each line contains its column- %% number and the additive-offset from the original value %% of the column. %% StackPlot(m, n, 'theColor') demonstrates itself with a %% random array of size [m+1 n]. The size defaults to %% [20 5]. % %% Copyright (C) 1996 Dr. Charles R. Denham, ZYDECO. %% All Rights Reserved. % %% Version of 5-Jun-96 at 12:07:42.99. %% Version of 28-Aug-1997 09:07:13. % %if nargin < 1, help(mfilename), varargin{1} = 20; end % %if isstr(varargin{1}) % if strcmp(varargin{1}, 'demo') % varargin{1} = 20; % else % varargin{1} = eval(varargin{1}); % end %end % %if length(varargin{1}) == 1 % m = varargin{1}; n = fix((m+3)./4); % if nargin > 1, n = varargin{2}; end % x = 1:m; % y = sin(sort(rand(m, n)) * n * pi); % figure('Name', 'StackPlot'); % if nargin < 3 % hh = stackplot(x, y); % else % theColor = varargin{3}; % hh = stackplot(x, y, theColor); % end % if exist('findpt') == 2 % findpt(hh) % end % if exist('zoomsafe') == 2 % zoomsafe % end % if nargout > 0, h = hh; end % return %end % %theYIndex = 1; %if nargin > 1 & ~isstr(varargin{2}) % theYIndex = 2; %end % %y = squeeze(varargin{theYIndex}); %y = reshape(y, size(y, 1), prod(size(y))./size(y, 1)); % %[m, n] = size(y); %if m > 1 % theMargin = (max(max(y)) - min(min(y))) ./ (10 .* n); % theOffset = zeros(1, n); % for j = 2:n % theOffset(j) = max(y(:, j-1)) - min(y(:, j)) + theMargin; % y(:, j) = y(:, j) + theOffset(j); % end %else % theOffset = 0; %end % %varargin{theYIndex} = y; % %hh = plot(varargin{:}); %for theIndex = 1:length(hh) % set(hh(theIndex), 'UserData', [theIndex theOffset(theIndex)]) %end % %if nargout > 0, h = hh; end fclose(fout); disp(' ## Installing: "starsafe.m" (text)') fout = fopen('starsafe.m', 'w'); %function [varargout] = starsafe(varargin) % %% starsafe -- Star symbols via "symbsafe". %% starsafe('demo') demonstrates itself. %% starsafe(N) demonstrates itself with N stars. %% starsafe(x0, y0, theSize, theColor, ...) calls "symbsafe" %% to draw five-pointed stars as patchs, centered on (x0, y0), %% with theSize and theColor. Additional name/value pairs are %% passed directly to the "patch" routine. The star sizes are %% given in the units of the y-axis. %% [xx, yy] = starsafe(...) returns the (x, y) coordinates of %% the stars, one per row, but does not plot them. %% h = starsafe(...) draws the stars and returns their handles. %% %% Also see: symbsafe, star. % %% Copyright (C) 2000 Dr. Charles R. Denham, ZYDECO. %% All Rights Reserved. %% Disclosure without explicit written consent from the %% copyright owner does not constitute publication. % %% Version of 13-Jan-2000 16:21:37. %% Updated 14-Jan-2000 15:47:04. % %if nargin > 1 % varargin = [{'star'} varargin]; %end % %if nargout > 0 % varargout = cell(1, nargout); % if nargin > 0 % [varargout{:}] = symbsafe(varargin{:}); % else % [varargout{:}] = symbsafe; % end %else % if nargin > 0 % symbsafe(varargin{:}); % else % symbsafe % end %end fclose(fout); disp(' ## Installing: "subplotsafe.m" (text)') fout = fopen('subplotsafe.m', 'w'); %function theHandle = subplotsafe(m, n, ind, jnd) % %% subplotsafe -- Subplot via Matlab indexing. %% subplotsafe(m, n, ind, jnd) returns the handle %% associated with the subplot that spans %% the (ind, jnd) indices in a template %% of size [m n] overall. If such a subplot %% already exists, having been created with %% this routine, it is made current. %% Note: we use regular Matlab array %% indexing here, rather than the counter- %% intuitive scheme of the "subplot" function. %% subplotsafe (no arguments) demonstrates itself. % %% Copyright (C) 2001 Dr. Charles R. Denham, ZYDECO. %% All Rights Reserved. %% Disclosure without explicit written consent from the %% copyright owner does not constitute publication. % %% Version of 18-Oct-2001 11:11:04. %% Updated 18-Oct-2001 16:22:05. % %if nargin < 1 % help(mfilename) % m = 5; % n = 2; % ind = 4:5; % jnd = 1:2; % feval(mfilename, m, n, ind, jnd) % s = [' ## ' mfilename '(' int2str(m) ', ' int2str(n) ', ' ... % mat2str(ind) ', ' mat2str(jnd) ')']; % disp(s) % return %end % %if nargin < 4, jnd = 1; end % %x = zeros(n, m); %x(:) = 1:prod(size(x)); %x = x'; % %% Create invisible figure of subplots. % %fig = figure('Visible', 'off', 'Units', 'normalized'); % %h = []; % Handles. %k = 0; % Counter. %kmax = prod([size(ind) size(jnd)]); %pos = zeros(kmax, 4); % %for j = jnd % for i = ind % k = k+1; % h(k) = subplot(m, n, x(i, j)); % pos(k, :) = get(h(k), 'Position'); % end %end % %delete(fig) % %% Measure the extent of the request. % %pos(:, 3:4) = pos(:, 3:4) + pos(:, 1:2); %pos(:, 1:2) = -pos(:, 1:2); %pos = max(pos); %pos(:, 1:2) = -pos(:, 1:2); %pos(:, 3:4) = pos(:, 3:4) - pos(:, 1:2); % %% Activate the existing subplot or create a new one. %% Careful: the Matlab "plot" command erases the %% "Tag" property of the "gca", so we cannot search %% for it here. % %oldUnits = get(gcf, 'Units'); % Save units. %set(gcf, 'Units', 'normalized') % Set to normalized units. % %ax = findobj(gcf, 'Type', 'axes', 'Position', pos); % %if any(ax) % h = ax(1); %else % h = axes('Position', pos, 'Tag', mfilename); % Create. %end % %axes(h) % %set(gcf, 'Units', oldUnits) % Restore units. % %if nargout > 0 % theHandle = h; %end fclose(fout); disp(' ## Installing: "super.m" (text)') fout = fopen('super.m', 'w'); %function theSuperObject = Super(theObject) % %% Super -- Super-object of an object. %% Super(theObject) returns the super-object %% of theObject, or [] if none exists. % %% Copyright (C) 1997 Dr. Charles R. Denham, ZYDECO. %% All Rights Reserved. %% Disclosure without explicit written consent from the %% copyright owner does not constitute publication. % %% Version of 04-Apr-1997 16:51:36. % %if nargin < 1, help(mfilename), return, end % %if isobject(theObject) % theStruct = struct(theObject); % else % theStruct = theObject; %end % %f = fieldnames(theStruct); %if ~isempty(f) % s = getfield(theStruct, f{length(f)}); % if ~isobject(s), s = []; end %end % %if nargout > 0 % theSuperObject = s; % else % disp(s) %end fclose(fout); disp(' ## Installing: "suspend.m" (text)') fout = fopen('suspend.m', 'w'); %function theResult = suspend(theValue) % %% suspend -- Control for suspending any process. %% suspend('demo') demonstrates itself. %% suspend (no arguments) creates or activates a pushbutton %% control labeled "Suspend" that can be used to guide the %% suspension of activities. %% suspend(0 or 1) sets/gets the state of the control. %% If the control-value is 1, suspend execution by using %% "keyboard" from within your procedure. After resuming, %% reset the control with "suspend(0)". %% suspend([]) deletes the control. %% %% Also see: keyboard. % %% Copyright (C) 2000 Dr. Charles R. Denham, ZYDECO. %% All Rights Reserved. %% Disclosure without explicit written consent from the %% copyright owner does not constitute publication. % %% Version of 26-Jul-2000 13:57:27. %% Updated 27-Jul-2000 13:45:47. % %persistent theControl % %% Constants. % %RED = [1 0 0]; %GREEN = [0 1 0]; %THE_TAG = '__Suspend__'; %N_DEMO = 3; % %% Demonstration. % %if nargin > 0 & isequal(theValue, 'demo') % disp([' ## Suspend this process ' int2str(N_DEMO) ... % ' times by clicking "Suspend".']) % suspend(0) % count = 0; % while count < N_DEMO % drawnow % Very important. % if suspend % count = count + 1; % disp([' ## Suspended at ' datestr(now)]) % disp([' ## Now entering "keyboard" mode ...']) % disp([' ## Type "r-e-t-u-r-n" to continue.']) % keyboard % disp(' ## Resuming ...') % suspend(0) % end % end % suspend([]) % disp(' ## Done') % return %end % %% Create or activate the control. % %if ~any(gcbo) % theFigure = findobj('Type', 'figure', 'Tag', THE_TAG); % if isempty(theFigure) % theFigure = figure('Name', 'Suspend', 'Visible', 'off', ... % 'Tag', THE_TAG, ... % 'CloseRequestFcn', 'suspend([])'); % theControl = uicontrol(theFigure, 'Style', 'PushButton', ... % 'String', 'Suspend', 'BackgroundColor', GREEN, ... % 'Callback', mfilename); % pos = get(theControl, 'Position'); % set(theControl, 'Position', [0 0 1 1] .* pos); % pos = [1 1 0 0] .* get(theFigure, 'Position') + ... % [0 0 1 1] .* get(theControl, 'Position'); % pos(1:2) = 20; % p = get(theFigure, 'Position'); % set(theFigure, 'Position', pos, 'Resize', 'off', 'Visible', 'on') % end % figure(theFigure) %end % %% Toggle the color-state via callback. % %if any(gcbo) & isequal(theControl, gcbo) % theColor = get(gcbo, 'BackGroundColor'); % if isequal(theColor, RED) % set(gcbo, 'BackgroundColor', GREEN) % else % set(gcbo, 'BackgroundColor', RED) % end % return %end % %% Set the color-state. % %if nargin > 0 % if ischar(theValue), theValue = eval(theValue); end % if isempty(theValue) % theFigure = findobj('Type', 'figure', 'Tag', THE_TAG); % delete(theFigure) % theControl = []; % return % elseif isequal(theValue, 0) % set(theControl, 'BackgroundColor', GREEN) % else % set(theControl, 'BackgroundColor', RED) % end %end % %% Get the color-state. % %if nargout > 0 % theColor = get(theControl, 'BackgroundColor'); % theResult = isequal(theColor, RED); % return %end fclose(fout); disp(' ## Installing: "swap.m" (text)') fout = fopen('swap.m', 'w'); %function swap(x, y) % %% swap -- Swap two variables. %% swap(x, y) swaps variables x and y in the %% caller's workspace, where they must have %% actual names. Note: no output arguments. % %% Copyright (C) 1998 Dr. Charles R. Denham, ZYDECO. %% All Rights Reserved. %% Disclosure without explicit written consent from the %% copyright owner does not constitute publication. % %% Version of 12-Nov-1998 15:21:41. % %if nargin < 2, help(mfilename), return, end % %assignin('caller', inputname(1), y) %assignin('caller', inputname(2), x) fclose(fout); disp(' ## Installing: "symbsafe.m" (text)') fout = fopen('symbsafe.m', 'w'); %function [x, y] = symbsafe(symb, x0, y0, theSize, theColor, varargin) % %% symbsafe -- Plot symbols. %% symbsafe('demo') demonstrates itself with stars %% or polygons. %% symbsafe(N) demonstrates itself with N stars. %% symbsafe (no argument) updates the existing symbols in all %% the axes of the current figure. The axes are left in %% in "manual" mode. %% symbsafe(symb, x0, y0, theSize, theColor, ...) draws symbols %% as patchs, centered on (x0, y0), with theSize and theColor. %% Additional name/value pairs are passed directly to the "patch" %% routine. The symb sizes are given in the units of the y-axis. %% The symb can be given as a two-column [x(:) y(:)] array of %% values, or as a function statement (with or without arguments) %% will be called with "[x, y] = eval(symb)". The (x, y) data %% are expected to be suitable for input to the Matlab "patch" %% routine. %% [xx, yy] = symbsafe(...) returns the (x, y) coordinates of %% the symbols, one per row, but does not plot them. %% h = symbsafe(...) draws the stars and returns their handles. %% %% Also see: arrowsafe, star (internal), polygon (internal). % %% Copyright (C) 2000 Dr. Charles R. Denham, ZYDECO. %% All Rights Reserved. %% Disclosure without explicit written consent from the %% copyright owner does not constitute publication. % %% Version of 13-Jan-2000 16:21:37. %% Updated 15-Jan-2000 16:04:58. % %if nargin < 3, y0 = 0; end %if nargin < 4, theSize = 1; end %if nargin < 5, theColor = [0 0 0]; end % %% Update. % %if nargin < 1 % oldGCA = gca; % h = findobj(gcf, 'Type', 'patch', 'Tag', mfilename); % if any(h) % for i = 1:length(h) % u = get(h(i), 'UserData'); % [xx, yy] = feval(mfilename, u{:}); % set(h(i), 'XData', xx, 'YData', yy) % end % end % axes(oldGCA) % return %end % %% Demonstration. % %if nargin == 1 % if isequal(symb, 'demo') % symb = ceil(rand(1, 1)*20 + 5); % end % n = symb; % if ischar(n), n = eval(n); end % f = findobj('Type', 'figure', 'Name', [mfilename ' demo']); % if any(f), figure(f(1)), else, figure, end % delete(findobj(gcf, 'Type', 'patch', 'Tag', mfilename)) % axis auto % x0 = (rand(1, n) - 0.5) * n; % y0 = rand(1, n) - 0.5; % s = rand(1, n)/10; % cmap = colormap; % index = floor(rand(prod(size(x0)), 1) * size(cmap, 1)) + 1; % c = cmap(index, :); % fcn = 'star'; % if rand(1, 1) > 0.5, fcn = 'polygon'; end % k = ceil(rand(1, 1)*8) + 2; % if rem(k, 4) == 0, k = k+1; end % fcn = [fcn '(' int2str(k) ')']; % feval(mfilename, fcn, x0, y0, s, c) % set(gca, 'XLim', [-n n], 'Ylim', [-1 1]) % set(gcf, 'Name', [mfilename ' demo']) % if exist('zoomsafe', 'file') == 2 % set(gcf, 'WindowButtonDownFcn', ... % ['if zoomsafe(''down''), ' mfilename ', end']) % end % feval(mfilename) % return %end % %if ischar(symb) % [xs, ys] = eval(symb); % "symb" may have arguments. %else % xs = symb(:, 1); % ys = symb(:, 2); %end % %if length(x0) == 1 % x0 = x0 * ones(size(y0)); %elseif length(y0) == 1 % y0 = y0 * ones(size(x0)); %end % %if length(theSize) == 1 % theSize = theSize * ones(size(x0)); %end % %if size(theColor, 1) == 1 % theColor = ones(prod(size(x0)), 1) * theColor; %end % %oldUnits = get(gca, 'Units'); %set(gca, 'Units', 'pixels') %thePosition = get(gca, 'Position'); %set(gca, 'Units', oldUnits) %theWidth = thePosition(3); %theHeight = thePosition(4); % %axis('manual') %dx = diff(get(gca, 'XLim')); %dy = diff(get(gca, 'YLim')); %dydx = dy / dx; % Not used. %dxdp = dx / theWidth; % sci/pixel. %dydp = dy / theHeight; % sci/pixel. % %scale = dxdp / dydp; % %f = zeros(1, 10); %f(2) = 1; %f = ifft(f)*length(f); %f(2:2:end) = f(2:2:end) * 0.38; %f(end+1) = f(1); %xs = -imag(f); %ys = real(f); % %if ischar(symb) % [xs, ys] = eval(symb); %else % xs = symb(:, 1); % ys = symb(:, 2); %end % %h = zeros(size(x0)); % %for i = 1:prod(size(x0)) % xsymb = xs * theSize(i) * scale + x0(i); % ysymb = ys * theSize(i) + y0(i); % csymb = theColor(i, :); % usymb = {symb, x0(i), y0(i), theSize(i)}; % if nargout == 2 % x(i, 1:length(xsymb)) = xsymb; % y(i, 1:length(ysymb)) = ysymb; % else % if length(varargin) > 1 % h(i) = patch(xsymb, ysymb, csymb, ... % 'Tag', mfilename, ... % 'UserData', usymb); % else % h(i) = patch(xsymb, ysymb, csymb, ... % 'Tag', mfilename, ... % 'UserData', usymb); % end % end %end % %set(gcf, 'ResizeFcn', mfilename) % %% ---------- star ---------- % % %function [x, y] = star(nPoints, theInnerRadius) % %% star -- Coordinates of a unit-star. %% [x, y] = star(nPoints) returns the (x, y) coordinates %% of a closed unit-star of nPoints (default = 5). If %% only one output argument is provided, the result %% is complex x+i*y. If none, a plot is made. The %% points go counterclockwise, starting at (x = 0, y = 1). %% [x, y] = star(nPoints, theInnerRadius) sets the radius %% of the valley points to theInnerRadius [0 .. 1]. % %% Copyright (C) 2000 Dr. Charles R. Denham, ZYDECO. %% All Rights Reserved. %% Disclosure without explicit written consent from the %% copyright owner does not constitute publication. % %% Version of 14-Jan-2000 12:48:41. %% Updated 15-Jan-2000 15:43:44. % %if nargin < 1 & nargout < 1 % nPoints = 'demo'; %elseif nargin < 1 % nPoints = 5; %end % %if isequal(nPoints, 'demo') % nPoints = 5; % plot(star(nPoints)) % set(gca, 'XLim', [-1 1], 'YLim', [-1 1]) % axis equal % set(gcf, 'Name', [mfilename ' demo']) % figure(gcf) % return %end % %if nargin < 1, nPoints = 5; end %if nargin < 2, theInnerRadius = 1; end % %if ischar(nPoints), nPoints = eval(nPoints); end % %zs = exp(sqrt(-1) * linspace(0, 2*pi, 2*nPoints+1)); %zs(end) = zs(1); %xs = -imag(zs); %ys = real(zs); % %if nargin > 1 % if ischar(theInnerRadius), theInnerRadius = eval(theInnerRadius); end % theScale = theInnerRadius; %else % Make valleys similar to Star of David. % k = [1 5]; % p = polyfit(xs(k), ys(k), 1); % q = polyfit(xs(k+2), ys(k+2), 1); % x0 = (q(2) - p(2)) / (p(1) - q(1)); % y0 = polyval(p, x0); % theScale = norm([x0 y0]); %end % %xs(2:2:end) = xs(2:2:end) * theScale; %ys(2:2:end) = ys(2:2:end) * theScale; % %if nargout > 1 % x = xs; y = ys; %elseif nargout > 0 % x = xs + sqrt(-1)*ys; %else % plot(xs, ys) %end % %% ---------- polygon ---------- % % %function [x, y] = polygon(nVertices) % %% polygon -- Unit-polygon coordinates. %% polygon('demo') demonstrates itself. %% [x, y] = polygon(nSides) returns the (x, y) %% coordinates for a closed unit-polygon of %% nVertices (default = 3). If only one output %% argument is provided, the result is complex %% x+i*y. If none, a plot is made. The points %% go counterclockwise, starting at (x = 0, y = 1). % %% Copyright (C) 2000 Dr. Charles R. Denham, ZYDECO. %% All Rights Reserved. %% Disclosure without explicit written consent from the %% copyright owner does not constitute publication. % %% Version of 15-Jan-2000 14:05:25. %% Updated 15-Jan-2000 15:43:44. % %if nargin < 1 & nargout < 1 % help(mfilename) % nVertices = 'demo'; %elseif nargin < 1 % nVertices = 5; %end % %if isequal(nVertices, 'demo') % nVertices = 5; % plot(polygon(nVertices)) % set(gca, 'XLim', [-1 1], 'YLim', [-1 1]) % axis equal % set(gcf, 'Name', [mfilename ' demo']) % figure(gcf) % return %end % %if ischar(nVertices), nVertices = eval(nVertices); end % %z = exp(sqrt(-1)*linspace(0, 2*pi, nVertices+1)); %z(end) = z(1); % %xx = -imag(z); %yy = real(z); % %if nargout > 1 % x = xx; % y = yy; %elseif nargout > 0 % x = xx + sqrt(-1)*yy; %else % plot(xx, yy) %end fclose(fout); disp(' ## Installing: "tensor_mul.m" (text)') fout = fopen('tensor_mul.m', 'w'); %function c = tensor_mul(a, b, ka, kb) % %% tensor_mul -- Tensor multiplication. %% tensor_mul(a, b, ka, kb) returns the tensor-product a*b, %% summed along the respective ka and kb directions, which %% must have the same length. If the directions are not %% specified, the innermost ones are assumed. %% tensor_mul('demo') demonstrates itself with two 2-by-2 %% random arrays. %% %% Also see: tensor_sol, tensor_test. % %% Copyright (C) 1998 Dr. Charles R. Denham, ZYDECO. %% All Rights Reserved. %% Disclosure without explicit written consent from the %% copyright owner does not constitute publication. % %% Version of 16-Sep-1998 05:34:15. % %if nargout > 0, c = []; end % %if nargin < 1, help(mfilename), a = 'demo'; end % %if isequal(a, 'demo') % a = floor(rand(2, 2) * 10); % b = floor(rand(2, 2) * 10); % ka = 2; kb = 1; % result = tensor_mul(a, b, ka, kb); % begets(mfilename, 4, a, b, ka, kb, result) % ka = 1; kb = 1; % result = tensor_mul(a, b, ka, kb); % begets(mfilename, 4, a, b, ka, kb, result) % ka = 1; kb = 2; % result = tensor_mul(a, b, ka, kb); % begets(mfilename, 4, a, b, ka, kb, result) % ka = 2; kb = 2; % result = tensor_mul(a, b, ka, kb); % begets(mfilename, 4, a, b, ka, kb, result) % return %end % %if nargin < 2, help(mfilename), return, end % %% Size of factors. % %sa = size(a); %sb = size(b); % %% Default directions. % %if nargin < 3, ka = length(sa); end %if nargin < 4, kb = 1; end % %% Check size compatibilities. % %if any(rem(ka, 1)) | ka < 1 | ka > length(sa) % s = num2str(ka); % warning([' ## First direction index incompatible: ' s '.']) % return %end % %if any(rem(kb, 1)) | kb < 1 | kb > length(sb) % s = num2str(kb); % warning([' ## Second direction index incompatible: ' s '.']) % return %end % %if sa(ka) ~= sb(kb) % s = [int2str(sa(ka)) ' ~= ' int2str(sb(kb))]; % warning([' ## Specified directions not same length: ' s '.']) % return %end % %% Size of product. % %sc = [sa sb]; %sc(length(sa)+kb) = []; %sc(ka) = []; % %% Permute a so ka is leftmost direction. % %pa = 1:length(sa); %if ka > 1 % pa(ka) = -pa(ka); % pa = abs(sort(pa)); % a = permute(a, pa); %end % %% Permute b so kb is leftmost direction. % %pb = 1:length(sb); %if kb > 1 % pb(kb) = -pb(kb); % pb = abs(sort(pb)); % b = permute(b, pb); %end % %% New sizes. % %sa = size(a); %sb = size(b); % %% Form two-dimensional arrays. % %a = reshape(a, [sa(1) prod(sa)/sa(1)]); %b = reshape(b, [sb(1) prod(sb)/sb(1)]); % %% Transpose a. % %pa = 1:length(sa); %pa([1 2]) = pa([2 1]); %a = permute(a, pa); % %% Matrix multiply and reshape. % %c = reshape(a * b, sc); fclose(fout); disp(' ## Installing: "tensor_sol.m" (text)') fout = fopen('tensor_sol.m', 'w'); %function x = tensor_sol(a, b, ka, kx) % %% tensor_sol -- Tensor solve. %% tensor_sol(a, b, ka, kx) solves for tensor x in a*x = b, %% for summations along the respective ka and kx directions. %% If the directions are not specified, the innermost ones %% are assumed. %% tensor_sol('demo') demonstrates itself with two 2-by-2 %% random arrays. %% %% Also see: tensor_mul, tensor_test. % %% Copyright (C) 1998 Dr. Charles R. Denham, ZYDECO. %% All Rights Reserved. %% Disclosure without explicit written consent from the %% copyright owner does not constitute publication. % %% Version of 16-Sep-1998 05:34:15. % %if nargout > 0, x = []; end % %if nargin < 1, help(mfilename), a = 'demo'; end % %if isequal(a, 'demo') % a = floor(rand(2, 2) * 10); % b = floor(rand(2, 2) * 10); % ka = 2; kx = 1; % result = tensor_sol(a, b, ka, kx); % begets(mfilename, 4, a, b, ka, kx, result) % ka = 1; kx = 1; % result = tensor_sol(a, b, ka, kx); % begets(mfilename, 4, a, b, ka, kx, result) % ka = 1; kx = 2; % result = tensor_sol(a, b, ka, kx); % begets(mfilename, 4, a, b, ka, kx, result) % ka = 2; kx = 2; % result = tensor_sol(a, b, ka, kx); % begets(mfilename, 4, a, b, ka, kx, result) % return %end % %if nargin < 2, help(mfilename), return, end % %% Size of factors. % %sa = size(a); %sb = size(b); % %% Default directions. % %if nargin < 3, ka = length(sa); end %if nargin < 4, kx = 1; end % %% Compatibility of sizes. % %u = sa; %u(ka) = []; %v = sb(1:length(u)); %if ~isequal(u, v) % s = [mat2str(sa) ' vs ' mat2str(sb)]; % warning([' ## Incompatible sizes: ' s '.']) % return %end % %% Size of result. % %sx = sb; %sx(1:length(sa)-1) = []; %ix = [1:length(sx) (kx-0.5)]; %sx = [sx sa(ka)]; %[ignore, ind] = sort(ix); %sx = sx(ind); % %% Check size compatibilities. % %if any(rem(ka, 1)) | ka < 1 | ka > length(sa) % s = num2str(ka); % warning([' ## First direction index incompatible: ' s '.']) % return %end % %if any(rem(kx, 1)) | kx < 1 | kx > length(sx) % s = num2str(kx); % warning([' ## Second direction index incompatible: ' s '.']) % return %end % %if sa(ka) ~= sx(kx) % s = [int2str(sa(ka)) ' ~= ' int2str(sx(kx))]; % warning([' ## Specified directions not same length: ' s '.']) % return %end % %% Permute a so ka is leftmost direction. % %pa = 1:length(sa); %if ka > 1 % pa(ka) = -pa(ka); % pa = abs(sort(pa)); % a = permute(a, pa); %end %sa = size(a); % %% Form two-dimensional a. % %a = reshape(a, [sa(1) prod(sa)/sa(1)]); %sa = size(a); % %% Transpose a. % %pa = 1:length(sa); %pa([1 2]) = pa([2 1]); %a = permute(a, pa); %sa = size(a); % %% Form two-dimensional b. % %b = reshape(b, [sa(1) prod(sb)/sa(1)]); % %% Matrix solve and reshape. % %x = reshape(a \ b, sx); % %% Inverse permutation of x. % %px = 1:length(sx); %if kx > 1 % px(kx) = -px(kx); % px = abs(sort(px)); % x = ipermute(x, px); %end fclose(fout); disp(' ## Installing: "tensor_test.m" (text)') fout = fopen('tensor_test.m', 'w'); %function tensor_test(ndims, len) % %% tensor_test -- Test of "tensor_mul" and tensor_sol". %% tensor_test(ndims, len) exercizes "tensor_mul" and %% "tensor_sol" with two random arrays, each with %% ndims, where each dimension has length len. %% All possible summation directions are tested. %% The elapsed time and an error-norm are displayed. %% %% Also see: tensor_mul, tensor_sol. % %% Copyright (C) 1998 Dr. Charles R. Denham, ZYDECO. %% All Rights Reserved. %% Disclosure without explicit written consent from the %% copyright owner does not constitute publication. % %% Version of 18-Sep-1998 08:41:32. % %help(mfilename) % %if nargin < 1, ndims = 3; end %if nargin < 2, len = 2; end % %if ischar(ndims), ndims = eval(ndims); end %if ischar(len), len = eval(len); end % %a = rand(ones(1, ndims)*len) - 0.5; %u = rand(ones(1, ndims)*len) - 0.5; % %err = zeros(ndims^2, 1); % %tic % %k = 0; % %for j = 1:ndims % disp([' ## Remaining: ' int2str(ndims^2 - k)]); % for i = 1:ndims % b = tensor_mul(a, u, i, j); % x = tensor_sol(a, b, i, j); % k = k+1; % e = x - u; % err(k) = norm(e(:)); % end %end % %toc % %err_norm = norm(err) fclose(fout); disp(' ## Installing: "terp4.m" (text)') fout = fopen('terp4.m', 'w'); %function zi = terp4(x, y, z, xi, yi) % %% terp4 -- Interpolate inside a quadralateral. %% terp('demo') demonstrates itself on a 10-by-10 %% grid. %% terp(N) demonstrates itself on an N-by-N grid, %% where N defaults to 10. %% terp4(x, y, z, xi, yi) interpolates z(x, y) %% at points (xi, yi), using the polynomial %% a*x*y + b*x + c*y + d = z, a saddle that %% is equivalent to bilinear interpolation %% on a rectangle. The data here can be %% arbitrary, so long as at least four %% of the (x, y) positions are unique. % %% Copyright (C) 2000 Dr. Charles R. Denham, ZYDECO. %% All Rights Reserved. %% Disclosure without explicit written consent from the %% copyright owner does not constitute publication. % %% Version of 26-Apr-2000 09:14:46. %% Updated 28-Apr-2000 15:45:01. % %if nargin < 1, help(mfilename), x = 'demo'; end % %if isequal(x, 'demo'), x = 10; end %if ischar(x), x = eval(x); end % %if length(x) == 1 % n = x; % x = [0 1 1 0]; % y = [0 0 1 1]; % z = rand(size(x)); % z = z - min(min(z)); z = z ./ max(max(z)); % xi = linspace(0, 1, n); % yi = linspace(0, 1, n); % [xi, yi] = meshgrid(xi, yi); % result = feval(mfilename, x, y, z, xi, yi); % surf(xi, yi, result) % rotate3d off % rotate3d on % return %end % %x = x(:); y = y(:); z = z(:); %a = [x.*y x y ones(size(x))]; %b = z(:); % %p = a \ b; % %theSize = size(xi); % %xi = xi(:); yi = yi(:); %zi = [xi.*yi xi yi ones(size(xi))] * p; % %zi = reshape(zi, theSize); fclose(fout); disp(' ## Installing: "throw.m" (text)') fout = fopen('throw.m', 'w'); %function theResult = throw(theThrownObject) % %% throw -- Throw an exception. %% throw(theThrownObject) throws an exception, %% which is expected to be handled by a try/catch %% block somewhere in the chain of callers. The %% thrown-object, which can be anything, is stored %% for later retrieval by the exception handler. %% throw (no argument) retrieves the thrown-object, %% then clears itself. If the handler cannot deal %% with the exception, it should re-throw it. % %% Copyright (C) 1998 Dr. Charles R. Denham, ZYDECO. %% All Rights Reserved. %% Disclosure without explicit written consent from the %% copyright owner does not constitute publication. % %% Version of 18-Aug-1998 09:29:02. % %persistent THROWN_OBJECT % %if nargin < 1 & nargout < 1 % help(mfilename) % return %end % %if nargin > 0 % THROWN_OBJECT = theThrownObject; % error(' ## No Exception Handler Available.') %end % %if nargout > 0 % theResult = THROWN_OBJECT; %end fclose(fout); disp(' ## Installing: "tmpname.m" (text)') fout = fopen('tmpname.m', 'w'); %function theResult = tmpname(extension) % %% tmpname -- File name suitable for temporary use. %% tmpname('extension') returns a non-existent filename with %% the given extension (default = none), suitable for use %% in the current directory. %% %% Also see: TEMPNAME, TEMPDIR. % %% Copyright (C) 2002 Dr. Charles R. Denham, ZYDECO. %% All Rights Reserved. %% Disclosure without explicit written consent from the %% copyright owner does not constitute publication. % %% Version of 02-Apr-2002 14:50:26. %% Updated 02-Apr-2002 14:50:26. % %TMP_PREFIX = 'tmp'; % %if nargin < 1, extension = ''; end % %while (1) % number = int2str(rand(1, 1)*10^10); % while length(number) < 10 % number = ['0' number]; % end % result = [TMP_PREFIX number extension]; % fp = fopen(result, 'r'); % if fp < 0, break, end % fclose(fp); %end % %if nargout > 0 % theResult = result; %else % assignin('caller', 'ans', result) % disp(result) %end fclose(fout); disp(' ## Installing: "tri_install.m" (text)') fout = fopen('tri_install.m', 'w'); %% Installer: "tri_install.m" %% Created: 30-Apr-2003 10:49:43. % %function bund_driver % %% bund_driver -- Driver for "bund" bundles. %% bund_driver (no arguments) contains Matlab commands %% to inflate the instructions and files that are %% encoded into the "bund_data" function of this package. % %% Copyright (C) 2001 Dr. Charles R. Denham, ZYDECO. %% All Rights Reserved. %% Disclosure without explicit written consent from the %% copyright owner does not constitute publication. % %% Version of 14-Jun-2001 10:54:16. %% Updated 06-Feb-2003 14:36:58. % %help(mfilename) % %v = version; %isVersion6 = (v(1) == '6'); % %BINARY_TAG = '?'; % %CR = char(13); %LF = char(10); % %comp = upper(computer); %if any(findstr(comp, 'PCWIN')) % Windows. % NL = [CR LF]; %elseif any(findstr(comp, 'MAC')) % Macintosh. % NL = CR; %else % Unix. % NL = LF; %end % %c = zeros(1, 256); %c(abs('0'):abs('9')) = 0:9; %c(abs('a'):abs('f')) = 10:15; % %disp([' ']) %disp([' ## This installer is ready to expand its contents,']) %disp([' ## starting in the present directory: "' pwd '"']) %disp([' ## To abort, execute an interruption now.']) %disp([' ## Otherwise, to continue, press any key.']) %disp([' ']) % %try % pause %catch % disp([' ## Installation interrupted.']) % disp([' ']) % return %end % %% eval('pause', 'disp(''Installation interrupted.''), return') % %tic % %w = which(mfilename); % %fin = fopen(w, 'r'); %if fin < 0, return, end % %found = ~~0; %while ~found % s = fgetl(fin); % if isequal(s, -1) % fclose(fin); % return % end % s = strrep(s, LF, ''); % Not necessary? % s = strrep(s, CR, ''); % Not necessary? % if isequal(s, 'function bund_data') % found = ~~1; % end %end % %fout = -1; % %done = ~~0; %while ~done % s = fgetl(fin); % if isequal(s, -1) % fclose(fin); % return % end % s = strrep(s, LF, ''); % Not necessary? % s = strrep(s, CR, ''); % Not necessary? % if length(s) > 0 % if s(1) ~= '%' % f = findstr(s, 'bund_setdir'); % if any(f) % theDir = eval(strrep(s, 'bund_setdir', '')); % [status, msg] = mkdir(theDir); % switch status % case 1 % if isVersion6 & any(msg) % disp([' ## Directory exists: "' theDir '"']) % else % disp([' ## Directory created: "' theDir '"']) % end % case 2 % disp([' ## Directory exists: "' theDir '"']) % otherwise % error([' ## Error while making new directory.']) % end % % try % cd(theDir) % catch % error([' ## Unable to go to directory: "' theDir '"']) % end % %% eval('cd(theDir)', ... %% 'disp(theDir), error('' ## Unable to go to directory.'')') % % else %% try %% eval(s); %% catch %% error([' ## Unable to evaluate: "' s '"']) %% end % %eval(s, ... % 'disp(s), error(''Unable to evaluate statement.'')') % % end % elseif length(s) > 1 & s(2) == BINARY_TAG % hx = double(s(3:end)); % Assume hex data. % bin = 16*c(hx(1:2:end)) + c(hx(2:2:end)); % fwrite(fout, bin, 'uchar'); % else % fprintf(fout, '%s', s(2:end)); % fprintf(fout, NL); % end % end %end % %fclose(fin); % %disp([' ## Elapsed time: ' num2str(fix(10*toc)/10) ' s.']) % %function bund_data %bund_setdir('tri') % %disp(' ## Installing: "areaxy.m" (text)') %fout = fopen('areaxy.m', 'w'); %%function theResult = areaxy(x, y) %% %%% areaxy -- Signed-area of polygon (x, y). %%% areaxy(x, y) returns the signed-area of the %%% polygon given by the (x, y) vertices. The %%% sign is positive for the counter-clockwise %%% sense; negative for clockwise. (The Matlab %%% "polyarea" result is unsigned.) %% %%% Copyright (C) 1999 Dr. Charles R. Denham, ZYDECO. %%% All Rights Reserved. %%% Disclosure without explicit written consent from the %%% copyright owner does not constitute publication. %% %%% Version of 08-Jul-1999 22:00:38. %%% Updated 08-Jul-1999 22:00:38. %% %%if nargin < 1, help(mfilename), return, end %% %%result = 0; %% %%if ~isempty(x) & length(x) == length(y) %% x = [x(:); x(1)]; %% y = [y(:); y(1)]; %% i = 1:length(x)-1; %% result = 0.5 * sum((x(i) .* y(i+1) - y(i) .* x(i+1))); %%end %% %%if nargout > 0 %% theResult = result; %%else %% disp(result) %% assignin('caller', 'ans', result) %%end %fclose(fout); % %disp(' ## Installing: "at.m" (text)') %fout = fopen('at.m', 'w'); %%function theResult = at(theFile, theOffset) %% %%% at -- Switch to the folder of a given file. %%% at('theFunction') switches to the folder of %%% 'theFunction', as determined by the "which" %%% function. %%% at('theFunction', theOffset) performs as above, %%% then marches into higher directories by the %%% amount of theOffset, which must be a negative %%% integer. %% %%% Copyright (C) 2000 Dr. Charles R. Denham, ZYDECO. %%% All Rights Reserved. %%% Disclosure without explicit written consent from the %%% copyright owner does not constitute publication. %% %%% Version of 01-Feb-2000 22:21:09. %%% Updated 22-Apr-2003 09:19:37. %% %%if nargout > 0, theResult = []; end %% %%if nargin < 1, help(mfilename), return, end %%if nargin < 2, theOffset = 0; end %%if ischar(theOffset), theOffset = eval(theOffset); end %% %%w = which(theFile); %% %%if isempty(w) %% w = which([theFile '/' theFile]); %% if isempty(w) %% disp([' ## No such file: ' theFile]) %% return %% end %%elseif isequal(w, 'built-in') %% disp([' ## ' theFile ' is built-in. Try "at ' theFile '.m".']) %% return %%end %% %%[thePath, theName, theExtension, theVersion] = fileparts(w); %% %%if any(thePath) %% cd(thePath) %% if theOffset < 0 %% for i = 1:fix(abs(theOffset)) %% cd .. %% end %% end %%end %% %%if nargout > 0 %% theResult = pwd; %%else %% disp([' ## ' pwd]) %%end %fclose(fout); % %disp(' ## Installing: "grid2tri.m" (text)') %fout = fopen('grid2tri.m', 'w'); %%function tri = grid2tri(m, n) %% %%% grid2tri -- Convert plaid-grid to triangles. %%% grid2tri(theSize) returns triangle indices for %%% a plaid-grid of theSize, as if each cell were %%% split into two triangles by a simple diagonal. %%% Indices run columnwise in conventional Matlab %%% fashion, and the triangles run counterclockwise. %%% grid2tri(m, n) is the same as grid2tri([m n]). %% %%% Copyright (C) 2001 Dr. Charles R. Denham, ZYDECO. %%% All Rights Reserved. %%% Disclosure without explicit written consent from the %%% copyright owner does not constitute publication. %% %%% Version of 16-Mar-2001 15:30:46. %%% Updated 16-Mar-2001 16:06:27. %% %%if nargin < 1 %% help(mfilename) %% m = 'demo'; %%end %% %%if isequal(m, 'demo') %% m = 2; n = 2; %%end %% %%if isstr(m), m = eval(m); end %%if nargin > 1 & isstr(n), n = eval(n); end %% %%if nargin < 2 %% if length(m) < 2 %% n = m; %% else %% n = m(2); %% m = m(1); %% end %%end %% %%% Fill a grid with one-dimensional indices. %% %%g = zeros(m, n); %%g(:) = 1:m*n; %% %%% Allocate the output array. %% %%t = zeros(2*(m-1)*(n-1), 3); %% %%% Two approaches: a slow one with nested for-loops, %%% and a very fast one that is fully vectorized. %% %%SLOW = 0; %% %%if SLOW %% k = 0; %% for j = 1:n-1 %% for i = 1:m-1 %% k = k+1; %% t(k, :) = [g(i, j) g(i+1, j) g(i+1, j+1)]; %% k = k+1; %% t(k, :) = [g(i, j) g(i+1, j+1) g(i, j+1)]; %% end %% end %%else %% temp = g(1:end-1, 1:end-1); % Upper left. %% temp = temp(:); %% t(1:2:end, 1) = temp; %% t(2:2:end, 1) = temp; %% temp = g(2:end, 1:end-1); % Lower left. %% t(1:2:end, 2) = temp(:); %% temp = g(2:end, 2:end); % Lower right. %% temp = temp(:); %% t(1:2:end, 3) = temp; %% t(2:2:end, 2) = temp; %% temp = g(1:end-1, 2:end); % Upper right. %% t(2:2:end, 3) = temp(:); %%end %% %%if nargout > 0 %% tri = t; %%else %% disp(t) %%end %fclose(fout); % %disp(' ## Installing: "inpoly.m" (text)') %fout = fopen('inpoly.m', 'w'); %%function theResult = inpoly(x, y, xi, yi) %% %%% inpoly -- In-polygon function, based on triangles. %%% inpoly(x, y, xi, yi) returns a logical vector that %%% describes whether the (xi, yi) points are inside %%% (TRUE) or outside (FALSE) the polygon given by %%% the (x, y) perimeter. %% %%% Copyright (C) 1999 Dr. Charles R. Denham, ZYDECO. %%% All Rights Reserved. %%% Disclosure without explicit written consent from the %%% copyright owner does not constitute publication. %% %%% Version of 12-Jul-1999 19:51:14. %%% Updated 12-Jul-1999 19:51:14. %% %%if nargout > 0, theResult = []; end %% %%if nargin < 4, help(mfilename), return, end %% %%if x(1) == x(end) & y(1) == y(end) %% x(end) = []; %% y(end) = []; %%end %% %%[xp, yp, tp] = tripoly(x, y); %% %%t = tsearch(xp, yp, tp, xi, yi); %%t(isnan(t)) = 0; %% %%s = (trisense(tp, xp, yp) > 0); %% %%result = zeros(size(t)); %%result(t ~= 0) = s(t(t ~= 0)); %% %%if nargout > 0 %% theResult = result; %%else %% disp(result) %% assignin('caller', 'ans', result) %%end %fclose(fout); % %disp(' ## Installing: "isconvex.m" (text)') %fout = fopen('isconvex.m', 'w'); %%function theResult = isconvex(x, y) %% %%% isconvex -- Is polygon (x, y) convex? %%% isconvex(x, y) returns TRUE if the (x, y) polygon %%% is convex (TRUE); otherwise, FALSE. %% %%% Copyright (C) 1999 Dr. Charles R. Denham, ZYDECO. %%% All Rights Reserved. %%% Disclosure without explicit written consent from the %%% copyright owner does not constitute publication. %% %%% Version of 12-Jul-1999 20:35:58. %%% Updated 12-Jul-1999 20:35:58. %% %%if nargin < 1, help(mfilename), return, end %% %%if x(1) == x(end) & y(1) == y(end) %% x(end) = []; %% y(end) = []; %%end %% %%tri = delaunay(x, y); %% %%h = trihull(tri); %% %%result = (length(h) == length(x)); %% %%if nargout > 0 %% theResult = result; %%else %% disp(result) %% assignin('caller', 'ans', result) %%end %fclose(fout); % %disp(' ## Installing: "polyangles.m" (text)') %fout = fopen('polyangles.m', 'w'); %%function [theResult, err] = polyangles(x, y) %% %%% polyangles -- Angles around a polygon. %%% polyangles('demo') calls polyangles(10). %%% polyangles(N) demonstrates itself by computing %%% the angles for a random N-sided polygon. %%% polyangles(x, y) returns the angles of the %%% polygon (x, y) vertices, in radians. Angles %%% for a counter-clockwise polygon will sum %%% to +2*pi radians; clockwise begets -2*pi. %%% polyangles(z) does the same for complex %%% polygon vertices z. %%% [result, err] = ... also returns the error %%% from a +/- 2*pi closure. %%% %%% Also see: polyrand. %% %%% Copyright (C) 2003 Dr. Charles R. Denham, ZYDECO. %%% All Rights Reserved. %%% Disclosure without explicit written consent from the %%% copyright owner does not constitute publication. %% %%% Version of 15-Apr-2003 17:03:24. %%% Updated 15-Apr-2003 17:03:24. %% %%if nargin < 1 %% help(mfilename) %% x = 'demo'; %%end %% %%if isequal(x, 'demo'), x = 10; end %%if ischar(x), x = eval(x); end %% %%if length(x) == 1 %% N = x; %% [x, y] = polyrand('demo', N); %% hold on, plot(x(1), y(1), 'r*'), hold off %% x = x + sqrt(-1)*y; %%end %% %%if nargin > 1 %% z = x + sqrt(-1)*y; %%else %% z = x; %%end %% %%z(end+1) = z(1); %%dz = diff(z); %%dz(end+1) = dz(1); %%dz = dz(2:end)./dz(1:end-1); %% %%angles = angle(dz); %% %%while any(angles < -pi) %% f = find(angles < -pi); %% angles(f) = angles(f) + pi; %%end %%while any(angles > pi) %% f = find(angles > pi); %% angles(f) = angles(f) - pi; %%end %% %%% Rearrange so angles correspond to vertex indices. %% %%result = zeros(size(angles)); %%result(1) = angles(end); %%result(2:end) = angles(1:end-1); %% %%% Error estimate. %% %%err = abs(abs(sum(result)) - 2*pi); %% %%if nargout > 0 %% theResult = result; %%else %% disp(result) %% assignin('caller', 'ans', result) %%end %fclose(fout); % %disp(' ## Installing: "polyrand.m" (text)') %fout = fopen('polyrand.m', 'w'); %%function [x, y] = polyrand(xx, yy) %% %%% polyrand -- Random non-intersecting polygon. %%% polyrand('demo', nVertices) demonstrates itself %%% with nVertices (default = 8). %%% [x, y] = polyrand(nVertices) returns the (x, y) %%% coordinates of a random polygon having nVertices. %%% In the event of (very rare) failure, the result %%% is empty. %%% [x, y] = polyrand(xx, yy) returns the (x, y) %%% coordinates for a polygon whose vertices are %%% (xx, yy). The sequence of vertices is not %%% necessarily unique. %%% z = ... returns the polygon as complex points %%% x + sqrt(-1)*y. %%% %%% Also see: TRIPLOT1, TRIHULL, TRI_REFLECT, DELAUNAY. %% %%% Copyright (C) 2002 Dr. Charles R. Denham, ZYDECO. %%% All Rights Reserved. %%% Disclosure without explicit written consent from the %%% copyright owner does not constitute publication. %% %%% Version of 06-Aug-2002 11:11:27. %%% Updated 17-Apr-2003 10:16:42. %% %%if nargin < 1, help(mfilename), xx = 'demo'; end %% %%if isequal(xx, 'demo') %% if nargin > 1 %% nVertices = yy; %% else %% nVertices = 8; %% end %% if ischar(nVertices), nVertices = eval(nVertices); end %% xx = rand(1, nVertices); %% yy = rand(size(xx)); %% hold off %% tri = delaunay(xx, yy); %% h = triplot1(tri, xx, yy); %% set(h, 'LineStyle', ':') %% iter = 0; %% while iter < 10 %% iter = iter + 1; %% [xo, yo] = feval(mfilename, xx, yy); %% if ~isempty(xo), break, end %% end %% if ~isempty(xo) %% hold on %% plot([xo xo(1)], [yo yo(1)], '-g', 'LineWidth', 2) %% hold off %% else %% disp([' ## Exceeded 10 iterations. Try again.']) %% end %% set(gca, 'XLim', [-0.05 1.05], 'YLim', [-0.05 1.05]) %% title([mfilename ' demo ' int2str(nVertices)]) %% xlabel x %% ylabel y %% try, zoomsafe, catch, end %% set(gcf, 'Name', 'PolyRand Demo') %% figure(gcf) %% if nargout > 1 %% x = xo; %% y = yo; %% elseif nargout > 0 %% x = xo + sqrt(-1)*yo; %% end %% return %%end %% %%if nargin < 2 %% nVertices = xx; %% if ischar(nVertices), nVertices = eval(nVertices); end %% xx = rand(1, nVertices); %% yy = rand(size(xx)); %%else %% nVertices = length(xx); %%end %% %%% Compute the convex hull. %% %%tri = delaunay(xx, yy); %%tri_original = tri; %% %%try %% hull = feval('convhull', xx, yy); %% hull(end) = []; %%catch %% hull = trihull(tri); %%end %% %%% Rotate to make minimum hull index first. %% %%f = find(hull == min(hull)); %%if length(f) == 1 %% hull = hull(:); %% hull = [hull(f:end); hull(1:f-1)]; %%else %% error(' ## Bad starting hull.') %%end %% %%% Eliminate one hull edge from the set, by deleting %%% its corresponding triangle. However, never %%% completely eliminate any point from the set. %%% Repeat until all the points are part of %%% the pseudo-hull. For variety, we randomly %%% rotate the current hull at each iteration. %% %%okay = ~~1; %%iter = 0; %% %%while okay & length(hull) < nVertices & iter < 3*nVertices %% %% iter = iter + 1; %% %% if (1) % Randomly rotate the hull for variety. %% [ignore, index] = sort(rand(size(hull))); %% if index(1) > 1 %% hull = [hull(index(1):end); hull(1:index(1)-1)]; %% end %% end %% %% okay = ~~0; %% %% hull(end+1) = hull(1); %% for i = 1:length(hull)-1 %% if sum(tri(:) == hull(i)) > 1 & ... %% sum(tri(:) == hull(i+1)) > 1 %% f = find(any(tri == hull(i), 2) & any(tri == hull(i+1), 2)); %% if any(f) %% t = tri(f, :); %% t(t == hull(i)) = []; %% t(t == hull(i+1)) = []; %% if ~any(t == hull) %% tri(f, :) = []; %% okay = ~~1; %% break %% end %% end %% end %% end %% %% if okay %% %% hull = [hull(1:i); t; hull(i+1:end)]; %% hull(end) = []; %% %% else % Unable to reach an interior point. %% %%% Find a point that is not yet in the pseudo-hull, but %%% connects directly to it. Find an opposing edge that %%% connects on both ends to the hull, and that can be %%% reflected. Reflect it, then continue processing. %% %% hull(end) = []; %% eligible = 1:nVertices; %% eligible(hull) = []; % Eligible vertices remaining. %% for j = 1:length(eligible) %% f = find(any(tri == eligible(j), 2)); %% for k = 1:length(f) %% t = tri(f(k), :); %% t(t == eligible(j)) = []; %% if any(t(1) == hull) & any(t(2) == hull) %% tri_new = tri_reflect(tri, xx, yy, t(1), t(2)); %% okay = ~isequal(tri_new, tri); %% if okay %%% disp([' ## Reflected ' mat2str(t)]) %% tri = tri_new; %% break %% else %%% disp([' ## Unable to reflect ' mat2str(t)]) %% end %% end %% end %% if okay, break, end %% end %% if ~okay %% disp([' ## No edge eligible for reflection.']) %% end %% end %%end %% %%% Verify that all vertices are included. %% %%okay = isequal(sort(hull(:).'), 1:nVertices); %% %%% If not, display the result. %% %%if ~okay %% disp(' ## Invalid result.') %% missing = 1:nVertices; %% missing(hull) = []; %% if ~isempty(missing) %% disp([' ## ' mfilename ': Missing vertex # ' mat2str(missing)]) %% end %% if (1) %% figure('Name', 'POLYRAND Error') %% subplot(1, 2, 1) %% h = triplot(tri_original, xx, yy); %% set(h, 'LineStyle', ':') %% limits = [-0.05 1.05]; %% set(gca, 'XLim', limits, 'YLim', limits) %% title('Original') %% subplot(1, 2, 2) %% h = triplot(tri, xx, yy); %% set(h, 'LineStyle', ':') %% xxx = xx(hull); xxx(end+1) = xxx(1); %% yyy = yy(hull); yyy(end+1) = yyy(1); %% hold on %% plot(xxx, yyy, 'g-', 'LineWidth', 2) %% set(gca, 'XLim', limits, 'YLim', limits) %% title('Erroneous') %% try, zoomsafe all, catch, end %% end %%end %% %%if okay %% xx = xx(hull); %% yy = yy(hull); %%else %% xx = []; %% yy = []; %%end %% %%if nargout > 1 %% x = xx; %% y = yy; %%elseif nargout > 0 %% x = xx + sqrt(-1)*yy; %%end %fclose(fout); % %disp(' ## Installing: "polytie.m" (text)') %fout = fopen('polytie.m', 'w'); %%function theSequence = polytie(i, j) %% %%% polytie -- Tie polygon edges together. %%% polytie(N) demonstrates itself for N points. %%% polytie(i, j) ties polygon edges (i, j) together into %%% a closed sequence, where each vertex i connects %%% to the corresponding j. Every vertex must appear %%% exactly twice in the [i j] data. %%% polytie([i j]) is an alternative syntax. %%% polytie(tri) returns the indices of the perimeter of %%% triangulation tri. %% %%% Copyright (C) 2002 Dr. Charles R. Denham, ZYDECO. %%% All Rights Reserved. %%% Disclosure without explicit written consent from the %%% copyright owner does not constitute publication. %% %%% Version of 11-Sep-2002 15:47:08. %%% Updated 30-Apr-2003 09:50:08. %% %%if nargin < 1, help(mfilename), i = 'demo'; return, end %% %%if isequal(i, 'demo'), i = 5; end %%if ischar(i), i = eval(i); end %% %%if length(i) == 1 %% n = i; %% x = rand(1, n); %% y = rand(size(x)); %% tri = delaunay(x, y); %% theSequence = feval(mfilename, tri); %% triplot1(tri, x, y) %% set(gcf, 'Name', [mfilename ' ' int2str(n)]) %% figure(gcf) %% return %%end %% %%[m, n] = size(i); %% %%if n == 3 % It is a triangulation. %% tri = i; %% t = [tri(:, [1 2]); tri(:, [2 3]); tri(:, [3 1])]; %% t = sort(t, 2); %% n = max(max(t)); %% s = sparse(t(:, 1), t(:, 2), 1, n, n); %% s(s > 1) = 0; %% [i, j] = find(s); %%elseif n == 2 % It is two columns [i j]. %% j = i(:, 2); %% i = i(:, 1); %%end %% %%t = [i(:) j(:)]; %% %%% To the (i, j) indices, append (j, i), %%% then sort. %% %%t = [t; t(:, [2 1])]; %% %%for k = [2 1] %% [ignore, indices] = sort(t(:, k)); %% t = t(indices, :); %%end %% %%i = t(:, 1); %%j = t(:, 2); %%m = max(max(t)); %%n = m; %% %%% Place the two entries for each index i %%% at rows 2*i-1 and 2*i. Zeros mark %%% unfilled indices. %% %%tt = zeros(2*max(max(t)), 2); %% %%[m, n] = size(t); %% %%for k = m-1:-2:1 %% kk = 2*t(k, 1)-1; %% tt([kk kk+1], :) = t([k k+1], :); %%end %% %%i = tt(:, 1); %%j = tt(:, 2); %% %%% Using a sparse maatrix, fill the (i, j) %%% entry with the vertex that edge (i, j) %%% points to. This can be vectorized. %% %%m = max(max(tt)); %%n = m; %% %%s = sparse(i(i ~= 0), j(j ~= 0), 1, m, n); %% %%[m, n] = size(tt); %% %%for k = 1:length(i) %% if i(k) > 0 %% kk = 2*j(k)-1; %% if j(kk) ~= i(k) %% s(i(k), j(k)) = j(kk); %% else %% s(i(k), j(k)) = j(kk+1); %% end %% end %%end %% %%i = i(i ~= 0); %%j = j(j ~= 0); %% %%i = i(1); %%j = j(1); %% %%[m, n] = size(t); %% %%sequence = zeros(m/2, 1); %%sequence(1) = i; %%sequence(2) = j; %% %%% Follow the sequence. %% %%for k = 3:m/2 %% next = s(i, j); %% sequence(k) = next; %% i = j; %% j = next; %%end %% %%if nargout > 0 %% theSequence = sequence; %%else %% assignin('caller', 'ans', sequence); %% disp(sequence) %%end %fclose(fout); % %disp(' ## Installing: "tri.m" (text)') %fout = fopen('tri.m', 'w'); %%function tri %% %%at(mfilename) %fclose(fout); % %disp(' ## Installing: "tri_bundle.m" (text)') %fout = fopen('tri_bundle.m', 'w'); %%function tri_bundle %% %%% tri_bundle -- Bundle the TRI directory. %%% tri_bundle (no argument) bundles the M-files %%% in the "tri" folder. %% %%% Copyright (C) 2003 Dr. Charles R. Denham, ZYDECO. %%% All Rights Reserved. %%% Disclosure without explicit written consent from the %%% copyright owner does not constitute publication. %% %%% Version of 29-Apr-2003 15:34:28. %%% Updated 29-Apr-2003 15:34:28. %% %%fclose('all'); %% %%at(mfilename) %% %%d = dir; %%i = 0; %%for k = 1:length(d) %% [pat, nam, ext, ver] = fileparts(d(k).name); %% if isequal(ext, '.m') %% i = i+1; %% theMFiles{i} = nam; %% end %%end %% %%for i = length(theMFiles):-1:1 %% if isequal(theMFiles{i}, 'tri_install') %% theMFiles(i) = []; %% end %%end %% %%theMFiles{end+1} = 'zoomsafe'; %%theMFiles{end+1} = 'at'; %% %%theMFiles = sort(theMFiles); %% %%theMessage = { %% ' ' %% ' ## Add the "tri" folder to your Matlab path.' %% ' ## Execute "polyrand" at the Matlab prompt.' %% ' ' %%}; %% %%bund new tri %%bund setdir tri %%bund('mfile', theMFiles) %%bund cd .. %%bund('disp', theMessage) %%bund close %% %%if (0) %% disp(' ## Manually delete "tri_install.m" if error occurs.') %% %% fclose('all'); %% %% at(mfilename) %% %% delete tri_install.m %% delete tri_install.p %% %% d = dir; %% for i = 1:length(d) %% theMFiles{i} = strrep(d(i).name, '.m', ''); %% end %% %% for i = length(theMFiles):-1:1 %% if isequal(theMFiles{i}, mfilename) %% theMFiles(i) = []; %% break %% end %% end %% %% theMFiles = [sort(theMFiles(:)); {'zoomsafe'}]; %% %% theMessage = { %% 'Restart Matlab, then execute "trisearch"' %% 'to see if the installation worked.' %% }; %% %% dst = 'tri_install'; %% %% self = bundle(dst, 'new'); %% %% self = add_setdir(self, 'tri'); %% self = add_mfile(self, theMFiles); %% self = add_message(self, theMessage); %% self = add_setdir(self, '..'); %% %% self = make_pcode(self); %%end %% %fclose(fout); % %disp(' ## Installing: "tri_reflect.m" (text)') %fout = fopen('tri_reflect.m', 'w'); %%function tri_out = tri_reflect(tri, x, y, i, j) %% %%% tri_reflect -- Reflect a triangulation edge. %%% tri_reflect(tri, x, y, i, j) reflects edge(i, j) in %%% in triangulation tri, whose vertices are (x, y). %%% That is, the two triangles that share vertices %%% (i, j) are reformed by replacing edge (i, j) %%% with an edge spanning the two non-shared %%% vertices. This is allowed only if such an %%% edge does not already exist, and if it would %%% not cross other edges if it did exist. On %%% input, all the triangles are expected to %%% have the same sense of rotation. %% %%% Copyright (C) 2002 Dr. Charles R. Denham, ZYDECO. %%% All Rights Reserved. %%% Disclosure without explicit written consent from the %%% copyright owner does not constitute publication. %% %%% Version of 07-Aug-2002 09:23:54. %%% Updated 07-Aug-2002 10:29:40. %% %%if nargin < 1, help(mfilename), tri = 'demo'; end %% %%if isequal(tri, 'demo') %% n = 4; %% x = rand(1, 4); %% y = rand(size(x)); %% tri = delaunay(x, y); %% a = [tri(:, 1:2); tri(:, 2:3); tri(:, [3 1])]; %% a = sort(a, 2); %% [ignore, ind] = sort(a); %% a = a(ind, :); %% d = diff(a); %% f = find(all(d == 0, 2)); %% if any(f) %% i = a(f(1), 1); %% j = a(f(1), 2); %% t = feval(mfilename, tri, x, y, i, j); %% subplot %% subplot(1, 2, 1) %% triplot(tri, x, y) %% title('Original') %% xlabel x %% ylabel y %% subplot(1, 2, 2) %% triplot(t, x, y) %% title('Reflected') %% xlabel x %% ylabel y %% if isequal(tri, t) %% title('Not Reflected') %% disp([' ## Edge (' int2str([i j]) ') cannot be flipped.']) %% end %% set(gcf, 'Name', 'Tri_Reflect Demo') %% figure(gcf) %% end %% return %%end %% %%for k = 1:length(i) %% %% f = find(any(tri == i(k), 2) & any(tri == j(k), 2)); %% %% if length(f) == 2 % A shared edge. %% a = find(tri(f(1), :) == i(k)); %% b = find(tri(f(1), :) == j(k)); %% if a == b-2 | a == b+1 %% f = flipud(f(:)); % Preserve sense. %% end %% a = tri(f(1), :); %% b = tri(f(2), :); %% a(a == i(k) | a == j(k)) = []; %% b(b == i(k) | b == j(k)) = []; %% g = find(any(tri == a, 2) & any(tri == b, 2)); %% if ~any(g) % No such edge; try to reflect it. %% tri_new = tri; %% tri_new(f(1), :) = [a i(k) b]; %% tri_new(f(2), :) = [b j(k) a]; %% s = trisense(tri, x, y); %% s_new = trisense(tri_new, x, y); %% if all(s == s_new) %% tri = tri_new; %% %% end %% end %% end %%end %% %%if nargout > 0 %% tri_out = tri; %%else %% assignin('caller', 'ans', tri) %%end %fclose(fout); % %disp(' ## Installing: "triage.m" (text)') %fout = fopen('triage.m', 'w'); %%function [triout, xout, yout, zout] = triage(tri, x, y, z) %% %%% triage -- Triangle repair. %%% [triout, xout, yout, zout] = triage(tri, x, y, z) performs %%% triage on the triangles "tri", whose vertices lie at (x, y, z), %%% so that the Matlab "tsearch" function can be applied, despite %%% concavities. The algorithm is: %%% 1. Cast existing "tri" to counter-clockwise sense. %%% 2. Fill all concavities and holes with clockwise %%% triangles that have at least one NaN vertex. %%% If a "z" vector is given, it will be made compatible %%% with the (xout, yout) values. Added boundary points %%% will be interpolated from the original z, and all %%% supplemental interior points will be set to NaN. %%% The output consists of the original triangles and %%% data at the top, followed by the supplemental items %%% at the bottom. %%% triage(N) demonstrates itself with N vertices (default = 32). %% %%% Copyright (C) 1999 Dr. Charles R. Denham, ZYDECO. %%% All Rights Reserved. %%% Disclosure without explicit written consent from the %%% copyright owner does not constitute publication. %% %%% Version of 09-Jul-1999 04:43:15. %%% Updated 30-Apr-2003 09:52:05. %% %%if nargin < 1, help(mfilename), tri = 'demo'; end %%if isequal(tri, 'demo'), tri = 32; end %%if ischar(tri), tri = eval(tri); end %% %%if length(tri) == 1 %% nvertices = tri; %% scale = nvertices^(1/4); %% rad = 1 + rand(nvertices, 1) / scale; %% ang = sort(rand(size(rad)) * 2 * pi); %% xy = rad .* exp(ang*sqrt(-1)); %% x = real(xy); y = imag(xy); %% %% [tt, xx, yy, ii] = tripoly(x, y); %% %% new = ones(size(x)); %% new(ii) = 0; %% new = find(new); %% xnew = xx(new); ynew = yy(new); %% %% s = trisense(tt, xx, yy); %% ccw = find(s > 0); %% cw = find(s < 0); %% if any(cw), tt(cw, :) = []; end %% [to, xo, yo] = feval(mfilename, tt, xx, yy); %% delete(get(gca, 'Children')) %% hold off %% h = tripatch(to, xo, yo); %% theBDF = [mfilename ' ' int2str(nvertices)]; %% set(h, 'ButtonDownFcn', theBDF) %% hold on, plot(x, y, 'o', xnew, ynew, '+'), hold off %% set(gca, 'XLim', [-2 2], 'YLim', [-2 2]) %% set(gcf, 'Name', theBDF) %% figure(gcf) %% zoomsafe %% return %%end %% %%if nargin < 3, help(mfilename), return, end %%if nargin < 4, z = zeros(size(x)); end %% %%x = x(:); y = y(:); z = z(:); %% %%trinew = []; %% %%s = trisense(tri, x, y); %%cw = (s < 0); ccw = (s > 0); %%tri(cw, :) = fliplr(tri(cw, :)); %% %%% disp(' ## trihull...') %%[h, overlapping] = trihull(tri); %% %%if ~overlapping %%% disp(' ## tripoly...') %% h = [NaN; h(:); NaN]; %% f = find(isnan(h)); %% %% kstart = 2; %% kstop = length(f); %% %% for k = kstart:kstop %% %% remaining = length(f)-k+1; %% if 0 & k == 2 | rem(remaining, 10) == 0 %% disp([' ## Remaining: ' int2str(remaining) ' segments.']) %% end %% %% hi = h(f(k-1)+1:f(k)-1); %% xhi = x(hi); yhi = y(hi); %% [ti, xi, yi, ind] = tripoly(xhi(:), yhi(:)); %% %%% Renumber and rearrange with old on top and new below. %% %% inserted = length(xi) - length(xhi); %% if any(inserted) %% disp([' ## "tripoly" has inserted ' int2str(inserted) ' points.']) %% %% old = ind; %% %% new = ones(size(xi)); %% new(old) = 0; %% new = find(new); %% %% htemp = [old(:); new(:)]; %% xi = xi(htemp); %% yi = yi(htemp); %% %% [ignore, hinv] = sort(htemp); %% ti = hinv(ti); %% %% old = 1:length(old); %% new = length(old) + (1:length(new)); %% old = old(:); %% new = new(:); %% %% hi_old = hi; %% hi_new = length(x) + [1:length(new)]; %% hi = [hi_old(:); hi_new(:)]; %% %% xi_new = xi(new); %% yi_new = yi(new); %% x = [x; xi_new(:)]; %% y = [y; yi_new(:)]; %% end %% %% ti = hi(ti); % Map to original indices. %% %% [m, n] = size(ti); %% if n == 1, ti = ti.'; end %% s = trisense(ti, x, y); %% cw = (s < 0); ccw = (s > 0); %% a(k-1) = areaxy(xi, yi); %% if a < 0 % cw %% ti = ti(ccw, :); %% else % ccw. %% ti = ti(cw, :); %% end %% trinew = [trinew; ti]; %% end %%end %% %%% Interpolate z for any new (x, y) points. %% %%if nargin > 3 & length(z) < length(x) %% inserted = (length(z)+1):length(x); %% z(length(x)) = 0; %% z(inserted) = triterp(trinew, x, y, z, x(inserted), y(inserted)); %%end %% %%xnew = []; ynew = []; znew = []; %% %%if ~isempty(trinew) %% [m, n] = size(trinew); %% if n == 1, trinew = trinew.'; end %% xnew = x(trinew); %% ynew = y(trinew); %% [m, n] = size(xnew); %% if n == 1, xnew = xnew.'; ynew = ynew.'; end %% xnew = xnew * [1;1;1] / 3; %% ynew = ynew * [1;1;1] / 3; %% znew = zeros(size(xnew)) + NaN; %%end %% %%xout = [x; xnew]; %%yout = [y; ynew]; %%if nargout > 3, zout = [z; znew]; end %% %%if ~isempty(trinew) %% k = (length(x) + (1:length(xnew))).'; %% trinew = [[trinew(:, [1 2]); trinew(:, [2 3]); trinew(:, [3 1])] [k; k; k]]; %% s = trisense(trinew, xout, yout); %% ccw = (s > 0); %% if any(ccw) %% trinew(ccw, :) = fliplr(trinew(ccw, :)); %% end %%end %% %%if nargout > 0 %% triout = [tri; trinew]; %%end %% %fclose(fout); % %disp(' ## Installing: "triarea.m" (text)') %fout = fopen('triarea.m', 'w'); %%function theResult = triarea(tri, x, y) %% %%% triarea -- Signed areas of triangles. %%% triarea(tri, x, y) returns the areas of the %%% triangles tri, whose vertices are (x, y), %%% such as returned by "delaunay". %% %%% Copyright (C) 1999 Dr. Charles R. Denham, ZYDECO. %%% All Rights Reserved. %%% Disclosure without explicit written consent from the %%% copyright owner does not constitute publication. %% %%% Version of 29-Apr-1999 08:20:50. %%% Updated 30-Apr-2003 09:55:04. %% %%if nargin < 1, help(mfilename), return, end %% %%t = tri(:, [1 2 3 1]); %% %%x = x(t); %%y = y(t); %% %%result = 0.5 .* ... %% (x(:, 1:3).*y(:, 2:4) - x(:, 2:4).*y(:, 1:3)) * ... %% ones(3, 1); %% %%if nargout > 0 %% theResult = result; %%else %% disp(result) %%end %fclose(fout); % %disp(' ## Installing: "triclean.m" (text)') %fout = fopen('triclean.m', 'w'); %%function [tout, xo, yo, io] = triclean(tri, x, y, ind, verbose) %% %%% triclean -- Triangle clean-up. %%% triclean(tri, x, y, ind) cleans-up the output of "tripoly" %%% by combining triangles and flipping quadralaterals that %%% involve "fake" points, until the interior triangles no %%% longer have any such points. The triangle vertices that %%% are indexed in "tri" correspond to the polygon perimeter %%% (x, y); the original polygon points (as output by "tripoly") %%% are indexed in "ind". The same information is returned, %%% now cleaned-up. Only the counter-clockwise triangles remain. %% %%% Copyright (C) 1999 Dr. Charles R. Denham, ZYDECO. %%% All Rights Reserved. %%% Disclosure without explicit written consent from the %%% copyright owner does not constitute publication. %% %%% Version of 26-Jul-1999 15:24:23. %%% Updated 29-Jul-1999 14:07:29. %% %%if nargin < 1, help(mfilename), return, end %%if nargin < 5, isVerbose = 0; end %% %%result = []; %% %%s = trisense(tri, x, y); %%ccw = find(s > 0); %%cw = find(s < 0); %% %%if any(cw), tri(cw, :) = []; end %% %%to = tri; xo = x; yo = y; io = ind; %% %%tic %% %%done = 0; %%while ~done %% done = 1; %% %%% In the first pass, we squeeze adjacent triangles %%% together, if they have a simple geometry. The %%% slowest lines are "f = find(to...)" and the next. %%% Also the calls to "trisort" and "uniq". %% %%to = [to(:, [1 2 3]); to(:, [1 3 2]); to(:, [2 1 3]); ... %% to(:, [2 3 1]); to(:, [3 1 2]); to(:, [3 2 1])]; %% %% squeezed = 1; %% while any(squeezed) %% squeezed = 0; %% fake = ones(size(xo)); %% fake(io) = 0; %% fake = find(fake); %% if isempty(fake), break, end %% if rem(length(fake), 10) == 0 %% disp([' ## Remaining: ' int2str(length(fake))]) %% end %% for k = 1:length(fake) %% node = fake(k); %% before = rem(node - 2 + length(xo), length(xo)) + 1; %% after = rem(node, length(xo)) + 1; %% f = find(to(:, 1) == before & to(:, 2) == node); % Slow 23-31%. %% g = find(to(:, 1) == node & to(:, 2) == after); % Slow 22-30%. %% for j = 1:length(g) %% for i = 1:length(f) %% if to(f(i), 3) == to(g(j), 3) %% opposite = to(f(i), 3); %% temp = sort([before opposite after]); %% indices = [1 2 3; 1 3 2; 2 1 3; ... %% 2 3 1; 3 1 2; 3 2 1]; %% tnew = temp(indices); %% if isVerbose %% disp([' ## Squeezed: ' int2str(node) ... %% ' ' mat2str(to(f(i), :)) ... %% ' ' mat2str(to(g(j), :)) ... %% ' ' mat2str(tnew(1, :))]) %% end %% h = find(any(to.' == node)); %% to(h(1:6), :) = tnew; %% to(h(7:end), :) = []; %% xo(node) = []; %% yo(node) = []; %% io(io == node) = []; %% io(io > node) = io(io > node) - 1; %% to(to > node) = to(to > node) - 1; %% squeezed = 1; %% done = 0; %% break %% end %% end %% if squeezed, break, end %% end %% if squeezed, break, end %% end %% end %% %% to = trisort(to); % Slow 7-13%. %% to = uniq(to); % Slow 7-12%. %% %% s = trisense(to, xo, yo); %% cw = (s < 0); %% if any(cw), to(cw, :) = fliplr(to(cw, :)); end %% %%% In the second pass, we flip one convex quadralateral %%% that involves a fake point. Then, we go back to %%% pass #1. %% %% [m, n] = size(to); %% to = [to(:, [1 2 3]); to(:, [1 3 2]); to(:, [2 1 3]); ... %% to(:, [2 3 1]); to(:, [3 1 2]); to(:, [3 2 1])]; %% %% indices = (1:m).'; %% indices = indices * ones(1, 6); %% to = [to indices(:)]; %% %% flipped = 1; %% %% while any(flipped) %% flipped = 0; %% flag = 0; %% fake = ones(size(xo)); %% fake(io) = 0; %% fake = find(fake); %% if isempty(fake), break, end %% for k = 1:length(fake) %% node = fake(k); %% f = find(to(:, 1) == node); %% for j = 1:length(f)-1 %% for i = j+1:length(f) %% if to(f(i), 2) == to(f(j), 2) %% a = node; %% b = to(f(i), 3); %% c = to(f(i), 2); %% d = to(f(j), 3); %% abcd = [a b c d]; %% xtemp = xo(abcd); %% ytemp = yo(abcd); %% if isconvex(xtemp, ytemp) %% if isVerbose %% disp([' ## Flipped: ' mat2str([a b c d])]) %% end %% triangle = to(f(i), 4); %% h = find(to(:, 4) == triangle); %% to(h(1), :) = [a b d triangle]; %% triangle = to(f(j), 4); %% h = find(to(:, 4) == triangle); %% to(h(1), :) = [b c d triangle]; %% flipped = 1; %% done = 0; %% break %% end %% end %% end %% if flipped, break, end %% end %% if flipped, break, end %% end %% flipped = 0; % Do just one. %% end %% %% to = to(1:m, 1:3); %% to = trisort(to); %% to = uniq(to); %% %% s = trisense(to, xo, yo); %% cw = (s < 0); %% if any(cw), to(cw, :) = fliplr(to(cw, :)); end %%end %% %%toc %% %%if nargout > 0 %% tout = to; %%else %% assignin('caller', 'ans', to) %%end %% %%fake = ones(length(x), 1); %%fake(ind) = 0; %%fake = find(fake); %% %%subplot(1, 2, 1) %%delete(get(gca, 'Children')) %%hold off %%axis normal %%tripatch(tri, x, y) %%hold on %%% plot(x(ind), y(ind), 'o-') %%plot(x(fake), y(fake), '+') %%hold off %%zoomsafe out %% %%fake = ones(length(xo), 1); %%fake(io) = 0; %%fake = find(fake); %% %%subplot(1, 2, 2) %%delete(get(gca, 'Children')) %%hold off %%axis normal %%tripatch(to, xo, yo) %%hold on %%% plot(xo(io), yo(io), 'o-') %%plot(xo(fake), yo(fake), '+') %%hold off %%zoomsafe out %% %%zoomsafe all %fclose(fout); % %disp(' ## Installing: "tridemo.m" (text)') %fout = fopen('tridemo.m', 'w'); %%function tridemo(nPoints) %% %%% tridemo -- Demonstration of "triage". %%% tridemo(nPoints) shows the result of applying %%% "triage" to a non-convex set of triangles, %%% based on nPoints random points (default = 10). %%% The original triangles are displayed in "green"; %%% the added ones are in "red"; and circles show %%% the locations of added "nanified" points. %%% Clicking on any triangle will cause the demo %%% to repeat itself with different points. %% %%% Copyright (C) 1999 Dr. Charles R. Denham, ZYDECO. %%% All Rights Reserved. %%% Disclosure without explicit written consent from the %%% copyright owner does not constitute publication. %% %%% Version of 12-Jul-1999 08:13:31. %%% Updated 12-Jul-1999 16:52:44. %% %%if nargin < 1, help(mfilename), nPoints = 'demo'; end %%if isequal(nPoints, 'demo'), nPoints = 10; end %%if ischar(nPoints), nPoints = eval(nPoints); end %% %%overlapping = 1; %% %%while overlapping %% x = rand(nPoints, 1); %% y = rand(nPoints, 1); %% tri = delaunay(x, y); %% %% index = 0; %% while any(index < 1 | index > nPoints) %% remove = ceil(sqrt(nPoints)); %% index = fix(nPoints * rand(1, remove)) + 1; %% end %% %% tri(index, :) = []; %% %% s = trisense(tri, x, y); %% tri(s < 0, :) = fliplr(tri(s < 0, :)); %% %% [th, overlapping] = trihull(tri); %% segments = sum(isnan(th)) + 1; %%end %% %%[to, xo, yo, zo] = triage(tri, x, y); %% %%s = trisense(to, xo, yo); %%cw = (s < 0); %%ccw = (s > 0); %% %%delete(get(gca, 'Children')) %% %%hold off %%if any(cw) %% h = trimesh(to(cw, :), xo, yo, 0*xo); %% set(h, 'FaceColor', [1 0 0]) %% set(h, 'ButtonDownFcn', ['tridemo ' int2str(nPoints)]) %% f = find(isnan(zo)); %% if any(f) %% hold on %% plot(xo(f), yo(f), 'ko') %% hold off %% end %%end %%hold on %%if any(ccw) %% h = trimesh(to(ccw, :), xo, yo, 0*xo); %% set(h, 'FaceColor', [0 1 0]) %% set(h, 'ButtonDownFcn', ['tridemo ' int2str(nPoints)]) %%end %%hold off %%view(2) %%zoomsafe %%set(gcf, 'Name', ['tridemo ' int2str(nPoints)]) %%figure(gcf) %fclose(fout); % %disp(' ## Installing: "trigui.m" (text)') %fout = fopen('trigui.m', 'w'); %%function [trio, xo, yo] = trigui(tri, x, y) %% %%% trigui -- Manipulate a triangulation. %%% trigui('demo') calls "trigui(10)". %%% trigui(N) demonstrates itself with N points %%% (default = 10). %%% trigui(tri, x, y) plots the triangulation (tri, x, y), %%% then allows the user to add/delete/move points by %%% manipulating vertices, edges, and triangles. Each %%% change forces the data to be re-triangulated. %%% trigui('method', x, y) uses the given 'method' %%% to triangulate the (x, y) data. The method %%% must return an array of indices, analogous %%% to the output of the 'delaunay' routine. %%% Although 'trigui' was written with triangles %%% in mind, any number of polygon vertices is %%% allowed, so long as there is an appropriate %%% 'method' to process them. %%% trigui(x, y) uses 'delaunay' to triangulate %%% the (x, y) data. %%% [trio, xo, yo] = trigui('get') returns the current %%% data. If only one argument is provided, a struct %%% of the current data is returned. %%% %%% Button #1 (Mac normal) on any item to drag it. %%% #2 (Mac shift-click) on a triangle to add a point. %%% #3 (Mac option-click) on any item delete it. %%% %%% To add an exterior point, add it within an existing %%% triangle, then drag it outside. %%% %%% While the mouse-button is down, its (x, y) position %%% is shown in the figure's title bar. %% %%% Copyright (C) 2002 Dr. Charles R. Denham, ZYDECO. %%% All Rights Reserved. %%% Disclosure without explicit written consent from the %%% copyright owner does not constitute publication. %% %%% Version of 13-Sep-2002 09:32:05. %%% Updated 29-Apr-2003 16:22:07. %% %%% Question: What is the region within which %%% a vertex can be moved without changing a %%% Delaunay tessellation? %% %%persistent theItem %%persistent theDownXY %%persistent theClone %% %%if nargin < 1, help(mfilename), tri = 'demo'; end %%if isequal(tri, 'demo'), tri = 10; end %% %%if ischar(tri) & any(tri(1) == '0123456789') %% tri = eval(tri); %%end %% %%if length(tri) == 1 %% n = tri; %% x = rand(1, n); %% y = rand(size(x)); %% tri = delaunay(x, y); %% feval(mfilename, tri, x, y); %% return %%end %% %%theBDF = [mfilename ' ButtonDownFcn']; %%theWBDF = [mfilename ' WindowButtonDownFcn']; %%theWBMF = [mfilename ' WindowButtonMotionFcn']; %%theWBUF = [mfilename ' WindowButtonUpFcn']; %% %%% Update the drawing. %% %%if nargin > 1 %% if nargin == 2 %% y = x; %% x = tri; %% tri = 'delaunay'; %% end %% if ischar(tri) %% theMethod = tri; %% tri = feval(theMethod, x, y); %% else %% theMethod = 'delaunay'; %% end %% theItem = []; %% theDownXY = []; %% theData = []; %% theData.tri = tri; %% theData.x = x; %% theData.y = y; %% theData.method = theMethod; %% set(gcf, 'UserData', theData) %% %% [m, n] = size(tri); %% %% % Plot polygons. %% %% if n > 2 %% t = tri; %% theTriangles = zeros(m, 1); %% delete(get(gca, 'Children')) %% hold off %% for i = 1:m %% xx = x(t(i, :)); %% yy = y(t(i, :)); %% theTriangles(i) = patch(xx, yy, 0*xx, ... %% 'FaceColor', 'y', ... %% 'EdgeColor', 'none', ... %% 'ButtonDownFcn', theBDF, ... %% 'UserData', t(i, :), ... %% 'Tag', 'polygon'); %% hold on %% end %% end %% %% % Plot edges. %% %% if n > 1 %% t = zeros(m*(n-1), 2); %% k = 0; %% for i = 1:n %% if i < n %% t(k+1:k+m, :) = tri(:, [i i+1]); %% else %% t(k+1:k+m, :) = tri(:, [i 1]); %% end %% k = k + m; %% end %% for i = [2 1] %% [ignore, indices] = sort(t(:, i)); %% t = t(indices, :); %% end %% d = diff(t); %% f = find(all(d == 0, 2)); %% t(f, :) = []; %% [m, n] = size(t); %% theEdges = zeros(m, 1); %% for i = 1:m %% xx = x(t(i, :)); %% yy = y(t(i, :)); %% theEdges(i) = plot(xx, yy, 'k-', ... %% 'LineWidth', 2.5, ... %% 'ButtonDownFcn', theBDF, ... %% 'UserData', t(i, :), ... %% 'Tag', 'edge'); %% end %% end %% %% % Plot vertices. %% %% theVertices = zeros(size(x)); %% for i = 1:length(x) %% theVertices(i) = plot(x(i), y(i), 'ko', ... %% 'MarkerFaceColor', 'k', ... %% 'ButtonDownFcn', theBDF, ... %% 'UserData', i, ... %% 'Tag', 'vertex'); %% end %% hold off %% set(gcf, 'ButtonDownFcn', theBDF) %% set(gcf, 'Pointer', 'arrow') %% set(gcf, 'Name', 'TriGUI') %% title('') %% figure(gcf) %% return %%end %% %%if ~ischar(tri), return, end %% %%p = get(gca, 'CurrentPoint'); %%px = p(1, 1); %%py = p(1, 2); %% %%theData = get(gcf, 'UserData'); %%theTri = theData.tri; %%theX = theData.x; %%theY = theData.y; %%theMethod = theData.method; %% %%theCommand = tri; %%theTag = get(gcbo, 'Tag'); %%theSelectionType = get(gcbf, 'SelectionType'); %% %%% Double-clicking: not invoked. %% %%CAN_DOUBLE_CLICK = ~~0; %%if CAN_DOUBLE_CLICK %% switch lower(theCommand) %% case 'buttondownfcn' %% if doubleclick %% theCommand = 'DoubleClickFcn' %% return %% end %% otherwise %% end %%end %% %%switch lower(theCommand) %% case 'get' %% if nargout < 2 %% trio = theData; %% else %% trio = theTri; %% xo = x; %% yo = y; %% end %% case 'buttondownfcn' %% set(gcf, 'Name', num2str([px py], 4)) %% switch lower(theTag) %% case {'vertex', 'edge', 'polygon'} %% theItem = gcbo; %% theDownXY = [px py]; %% set(gcf, 'Pointer', 'circle') %% theIndices = get(theItem, 'UserData'); %% theColor = 'g'; %% if length(theIndices) < 3 %% theClone = line( ... %% theX(theIndices), theY(theIndices), ... %% 'Color', theColor, ... %% 'Marker', 'o', 'LineStyle', '-', ... %% 'EraseMode', 'xor'); %% else %% theClone = patch( ... %% theX(theIndices), theY(theIndices), ... %% theColor, ... %% 'Marker', 'o', 'LineStyle', '-', ... %% 'EraseMode', 'xor'); %% end %% otherwise %% end %% switch lower(theTag) %% case 'vertex' %% set(theItem, 'MarkerEdgeColor', 'r', ... %% 'MarkerFaceColor', 'r') %% case 'edge' %% % theItem = gcbo; %% set(theItem, 'Color', 'r') %% case 'polygon' %% % theItem = gcbo; %% set(theItem, 'FaceColor', 'r') %% otherwise %% end %% switch lower(theTag) %% case {'vertex', 'edge', 'polygon'} %% theIndices = get(theItem, 'UserData'); %% switch lower(theSelectionType) %% case 'extend' %% switch lower(theTag) %% case 'polygon' %% theX(end+1) = px; %% theY(end+1) = py; %% feval(mfilename, theMethod, theX, theY) %% otherwise %% end %% case 'alt' %% [m, n] = size(theTri); %% if length(theX) - length(theIndices) >= n %% theX(theIndices) = []; %% theY(theIndices) = []; %% end %% feval(mfilename, theMethod, theX, theY) %% otherwise %% set(gcf, 'WindowButtonMotionFcn', theWBMF) %% set(gcf, 'WindowButtonUpFcn', theWBUF) %% end %% otherwise %% end %% case 'windowbuttondownfcn' %% case 'windowbuttonmotionfcn' %% set(gcf, 'Name', num2str([px py], 4)) %% dx = px - theDownXY(1); %% dy = py - theDownXY(2); %% theIndices = get(theItem, 'UserData'); %% x = theX(theIndices) + dx; %% y = theY(theIndices) + dy; %% set(theClone, 'XData', x, 'YData', y); %% case 'windowbuttonupfcn' %% set(gcf, 'Name', num2str([px py], 4)) %% theTag = get(theItem, 'Tag'); %% set(gcf, 'WindowButtonMotionFcn', '') %% set(gcf, 'WindowButtonUpFcn', '') %% set(gcf, 'Pointer', 'arrow') %% dx = px - theDownXY(1); %% dy = py - theDownXY(2); %% switch lower(theTag) %% case {'edge', 'vertex', 'polygon'} %% delete(theClone) %% theClone = []; %% theIndices = get(theItem, 'UserData'); %% theX(theIndices) = theX(theIndices) + dx; %% theY(theIndices) = theY(theIndices) + dy; %% feval(mfilename, theMethod, theX, theY) %% otherwise %% end %% theItem = []; %% theDownXY = []; %% otherwise %% disp([' ## ' theCommand ' ' theType]) %%end %fclose(fout); % %disp(' ## Installing: "trihull.m" (text)') %fout = fopen('trihull.m', 'w'); %%function [theHull, nonUnique] = trihull(theTri) %% %%% trihull -- Indices of boundary of triangulation. %%% trihull(theTri) returns the indices of the bounding %%% polygon associated with theTri triangulation. This %%% corresponds to the convex-hull if the triangles form %%% a filled convex set. For triangulations that contain %%% holes, the individual segments are separated by NaNs. %%% [theHull, nonUnique] = trihull(theTri) also returns %%% nonUnique = TRUE (non-zero) if any point appears in %%% more than one segment. %% %%% Copyright (C) 1999 Dr. Charles R. Denham, ZYDECO. %%% All Rights Reserved. %%% Disclosure without explicit written consent from the %%% copyright owner does not constitute publication. %% %%% Version of 02-Jul-1999 17:02:50. %%% Updated 30-Apr-2003 10:19:13. %% %%if nargin < 1 %% help(mfilename) %% theTri = 'demo'; %%end %% %%if isequal(theTri, 'demo'), theTri = 10; end %%if ischar(theTri), theTri = eval(theTri); end %% %%if length(theTri) == 1 %% try %% nPoints = theTri; %% x = rand(nPoints, 1); y = rand(size(x)); %% tri = delaunay(x, y); %% h = feval(mfilename, tri); %% trimesh(tri, x, y, x*0) %% view(2) %% px = x(h); py = y(h); %% px(end+1) = px(1); py(end+1) = py(1); %% hold on %% plot(px, py, '-bo') %% hold off %% f = findobj(gcf, 'Type', 'patch'); %% theBDF = [mfilename ' ' int2str(nPoints)]; %% title(theBDF) %% set(f, 'buttondownfcn', theBDF) %% set(gcf, 'Name', [mfilename ' Demo']) %% zoomsafe %% figure(gcf) %% if nargout > 0, theHull = h; end %% return %% catch %% disp([' ## ' mfilename ' error.']) %% disp([' ## ' lasterr]) %% disp([' ## ' mfilename ' needs work.']) %% return %% end %%end %% %%t = [theTri(:, [1 2]); theTri(:, [2 3]); theTri(:, [3 1])]; %% %%m = max(max(t)); n = m; %% %%s = sparse(t(:, 1), t(:, 2), ones(size(t(:, 1))), m, n); %% %%t = sort(t.').'; %%s1 = sparse(t(:, 1), t(:, 2), ones(size(t(:, 1))), m, n); %% %%s1 = s1 + s1.'; %% %%[i, j] = find(s == 1 & s1 == 1); % Too slow. %% %%[i, indices] = sort(i); %%j = j(indices); %% %%connect(i) = j; %% %%h = zeros(size(i)); %%f = find(connect); %%f = f(1); %%h(1) = connect(f); %%connect(f) = 0; %%starts(1) = 1; %% %%for k = 2:length(h) %%% remaining = length(h)-k+1; %%% if rem(remaining, 1000) == 0 & k > 2 %%% disp([' ## Remaining: ' int2str(remaining) ' edges.']) %%% end %% if connect(h(k-1)) %% h(k) = connect(h(k-1)); %% connect(h(k-1)) = 0; %% else %% f = find(connect); %% if any(f) %% f = f(1); %% h(k) = connect(f); %% connect(f) = 0; %% starts(end+1) = k; %% else %% break %% end %% end %%end %% %%if 0 & length(starts) > 1 %% disp([' ## Segments: ' int2str(length(starts))]) %%end %% %%% Check perimeters for points represented more than once. %% %%htemp = h(h ~= 0); %%s = sparse(htemp, htemp, ones(size(htemp))); %%[i, j] = find(s > 1); %%nonUnique = any(i); %%if nonUnique & nargout < 2 %% disp([' ## ' mfilename ': Some perimeters overlap.']) %%end %% %%if length(starts) > 1 %% htemp = []; %% starts(end+1) = length(h) + 1; %% for k = 1:length(starts)-1 %% i = starts(k):starts(k+1)-1; %% if k > 1, htemp = [htemp; NaN]; end %% htemp = [htemp; h(i)]; %% end %% h = htemp; %%end %% %%if nargout > 0 %% theHull = h; %%else %% assignin('caller', 'ans', h) %%end %fclose(fout); % %disp(' ## Installing: "trihull1.m" (text)') %fout = fopen('trihull1.m', 'w'); %%function h = trihull1(tri) %% %%% trihull1 -- Alternative to TRIHULL. %%% trihull1('demo') demonstrates itself. %%% trihull1(N) demonstrates itself with N points. %%% trihull1(tri) returns the convex-hull %%% for triangulation tri. Does not employ %%% sparse matrices. %%% %%% This is an attempt to accelerate the process, %%% but alas, TRIHULL is 3x faster. Evidently, %%% the sparse matrix operations are very quick. %%% %%% Also see: TRIHULL, TRIPLOT, DELAUNAY. %% %%% Copyright (C) 2002 Dr. Charles R. Denham, ZYDECO. %%% All Rights Reserved. %%% Disclosure without explicit written consent from the %%% copyright owner does not constitute publication. %% %%% Version of 07-Aug-2002 18:47:49. %%% Updated 30-Apr-2003 10:49:27. %% %%if nargin < 1, tri = 'demo'; end %%if isequal(tri, 'demo'), tri = 10; end %%if ischar(tri), tri = eval(tri); end %% %%if length(tri) == 1 %% try %% n = tri; %% x = rand(1, n); %% y = rand(size(x)); %% tri = delaunay(x, y); %% hh = feval(mfilename, tri); %% hhh = trihull(tri); %% f = find(hhh == min(hhh)); %% if f > 1 %% hhh = [hhh(f:end); hhh(1:f-1)]; %% end %% if ~isequal(hh, hhh) %% disp([' ## TRIHULL1 result not same as TRIHULL result.']) %% end %% hold off %% hhh = [hh; hh(1)]; %% plot(x(hhh), y(hhh), 'g-', 'LineWidth', 3) %% hold on %% triplot(tri, x, y) %% title([mfilename ' ' int2str(n)]) %% xlabel x %% ylabel y %% limits = [-0.05 1.05]; %% set(gca, 'XLim', limits, 'YLim', limits) %% set(gcf, 'Name', 'TriHull1 Demo') %% try, zoomsafe, catch, end %% figure(gcf) %% return %% catch %% disp([' ## ' mfilename ' error.']) %% disp([' ## ' lasterr]) %% disp([' ## ' mfilename ' needs work.']) %% return %% end %%end %% %%t = [tri(:, [1 2]); tri(:, [2 3]); tri(:, [3 1])]; %% %%t1 = sort(t, 2); %%t2 = t; %% %%[ignore, i] = sort(t1(:, 2)); %%t1 = t1(i, :); %%t2 = t2(i, :); %%[ignore, i] = sort(t1(:, 1)); %%t1 = t1(i, :); %%t2 = t2(i, :); %% %%% Keep only unique edges. %% %%d = diff(t1); %%f = find(all(d == 0, 2)); %%g = sort([f; f+1]); %%g(diff(g) == 0) = []; %%t2(g, :) = []; %% %%% Make a transition list. %% %%j = zeros(max(t2(:, 1)), 1); %% %%j(t2(:, 1)) = t2(:, 2); %%f = find(j > 0); %%f = f(1); %% %%% Traverse the list. %% %%[m, n] = size(t2); %%h = zeros(m, 1); %%for i = 1:length(h) %% h(i) = f; %% f = j(f); % Trouble here. %%end %fclose(fout); % %disp(' ## Installing: "trilabel.m" (text)') %fout = fopen('trilabel.m', 'w'); %%function theTextHandles = trilabel(tri, x, y, varargin) %% %%% trilabel -- Label plot of triangulation. %%% trilabel (no argument) demonstrates itself. %%% trilabel(tri, x, y, ...) labels the vertices and %%% triangles of triangulation tri, as either 1..N %%% or 0:N-1, depending on the base of the "tri" %%% indices. The handles of the text-objects are %%% returned. %% %%% Copyright (C) 2001 Dr. Charles R. Denham, ZYDECO. %%% All Rights Reserved. %%% Disclosure without explicit written consent from the %%% copyright owner does not constitute publication. %% %%% Version of 30-Jul-2001 14:32:13. %%% Updated 11-Sep-2002 21:04:15. %% %%% Demonstration. %% %%if nargin < 1 %% %% help(mfilename) %% %% tri = [ %% 0 1 7 %% 1 2 3 %% 3 4 5 %% 5 6 7 %% 7 3 5 %% 7 1 3 %% ]; %% %% lonlat = [ %% -124.018048 46.694592 1 %% -124.044816 46.668488 1 %% -124.017968 46.650984 1 %% -123.992400 46.664772 1 %% -123.964264 46.646212 1 %% -123.929744 46.673788 1 %% -123.956592 46.696068 1 %% -123.991760 46.683868 1 %% ]; %% %% x = lonlat(:, 1); %% y = lonlat(:, 2); %% %% triplot(tri+1, x, y) %% %%end %% %%isZero = (min(tri(:)) == 0); %% %%t = [tri(:, 1:2); tri(:, 2:3); tri(:, 3:-2:1)]; %% %%tt = t.'; %%if isZero %% tt = tt + 1; %%end %% %%x = x(:).'; %%y = y(:).'; %% %%xx = x(tt); %%yy = y(tt); %% %%if (0) % Legacy of TRIPLOT1. %% if nargin < 4 %% h = plot(xx, yy, 'b-'); %% else %% h = plot3(xx, yy, 'b-', varargin{:}); %% end %%end %% %%k = 1:length(x); %%if isZero %% k = k - 1; %%end %% %%label = cell(size(x)); %%for i = 1:length(x) %% index = k(i); %% label{i} = int2str(index); %%end %% %%h1 = text(x, y, label, 'Color', 'k', ... %% 'HorizontalAlignment', 'center', ... %% 'VerticalAlignment', 'middle', ... %% 'FontWeight', 'bold', 'FontSize', 12, ... %% 'Tag', [mfilename 'vertex']); %% %%t = tri.'; %%if isZero, t = t + 1; end %% %%xx = mean(x(t)); %%yy = mean(y(t)); %% %%[m, n] = size(tri); %%k = 1:m; %%if isZero, k = k - 1; end %% %%label = cell(size(xx)); %%for i = 1:length(k) %% index = k(i); %% label{i} = int2str(index); %%end %% %%h2 = text(xx, yy, label, 'Color', 'r', ... %% 'HorizontalAlignment', 'center', ... %% 'VerticalAlignment', 'middle', ... %% 'FontWeight', 'bold', 'FontSize', 12, ... %% 'Tag', [mfilename 'triangle']); %% %%if nargout > 0, theTextHandles = [h1; h2]; end %fclose(fout); % %disp(' ## Installing: "tripatch.m" (text)') %fout = fopen('tripatch.m', 'w'); %%function theHandles = tripatch(tri, x, y, z) %% %%% tripatch -- Plot triangles w/r to sense. %%% tripatch(tri, x, y, z) plots the triangles tri, %%% using green for counter-clockwise sense and %%% red for clockwise. The patch-handles are %%% returned. %% %%% Copyright (C) 1999 Dr. Charles R. Denham, ZYDECO. %%% All Rights Reserved. %%% Disclosure without explicit written consent from the %%% copyright owner does not constitute publication. %% %%% Version of 22-Jul-1999 13:31:09. %%% Updated 30-Apr-2003 10:23:13. %% %%if nargin < 3, help(mfilename), return, end %%if nargin < 4, z = 0*x; end %% %%red = [1 0 0]; %%green = [0 1 0]; %%blue = [0 0 1]; %%white = red + blue + green; %%black = 0*white; %% %%[m, n] = size(tri); %% %%theSense = trisense(tri, x, y); %%ccw = find(theSense > 0); %%cw = find(theSense < 0); %% %%h = [NaN; NaN]; %% %%wasHold = ishold; %% %%if any(cw) %% t = tri(cw, :).'; %% if nargin < 4 %% h(2) = patch(x(t), y(t), red, 'EdgeColor', black); %% else %% h(2) = patch(x(t), y(t), z(t), red, 'EdgeColor', black); %% end %% hold on %%end %% %%if any(ccw) %% t = tri(ccw, :).'; %% if nargin < 4 %% h(1) = patch(x(t), y(t), green, 'EdgeColor', white); %% else %% h(1) = patch(x(t), y(t), z(t), green, 'EdgeColor', white); %% end %%end %% %%if ~isnan(h(2)) %% set(h(2), 'EdgeColor', black) %%end %% %%if ~isnan(h(1)) %% set(h(1), 'EdgeColor', white) %%end %% %%if ~wasHold, hold off, end %% %%if nargout > 0, theHandles = h; end %fclose(fout); % %disp(' ## Installing: "triperim.m" (text)') %fout = fopen('triperim.m', 'w'); %%function thePerimeter = triperim(theTri) %% %%% triperim -- Indices of triangulation perimeter. %%% triperim(theTri) returns the indices of points %%% comprising the perimeter of theTri triangulation. %%% %%% Also see: POLYTIE. %% %%% Copyright (C) 2002 Dr. Charles R. Denham, ZYDECO. %%% All Rights Reserved. %%% Disclosure without explicit written consent from the %%% copyright owner does not constitute publication. %% %%% Version of 11-Sep-2002 11:54:10. %%% Updated 30-Apr-2003 10:24:18. %% %%if nargin < 1, help(mfilename), return, end %% %%p = polytie(theTri); %% %%if nargout > 0 %% thePerimeter = p; %%else %% assignin('caller', 'ans', p) %%end %fclose(fout); % %disp(' ## Installing: "triplot1.m" (text)') %fout = fopen('triplot1.m', 'w'); %%function theHandle = triplot1(tri, x, y, varargin) %% %%% triplot1 -- Simple plot of triangulation. %%% triplot1('demo') demonstrates itself with %%% some hard-wired data. %%% triplot1(N) demonstrates itself with a %%% triangulation of N points (default = 8). %%% triplot1(tri, x, y, ...) plots the given triangulation, %%% whose indices are "tri", and whose positions are %%% (x, y). Additional name/value pairs are passed %%% directly to the "plot" command. The vertices and %%% triangles are labeled, either 1..N or 0..N-1, %%% depending on the base of the "tri" indices. %% %%% Copyright (C) 2001 Dr. Charles R. Denham, ZYDECO. %%% All Rights Reserved. %%% Disclosure without explicit written consent from the %%% copyright owner does not constitute publication. %% %%% Version of 30-Jul-2001 14:32:13. %%% Updated 30-Jul-2001 14:32:13. %% %%% Demonstration. %% %%if nargin == 1 & isequal(tri, 'demo') %% %% help(mfilename) %% %% tri = [ %% 0 1 7 %% 1 2 3 %% 3 4 5 %% 5 6 7 %% 7 3 5 %% 7 1 3 %% ]; %% %% lonlat = [ %% -124.018048 46.694592 1 %% -124.044816 46.668488 1 %% -124.017968 46.650984 1 %% -123.992400 46.664772 1 %% -123.964264 46.646212 1 %% -123.929744 46.673788 1 %% -123.956592 46.696068 1 %% -123.991760 46.683868 1 %% ]; %% %% x = lonlat(:, 1); %% y = lonlat(:, 2); %%end %% %%if nargin < 1, tri = 8; end %%if ischar(tri), tri = eval(tri); end %% %%if length(tri) == 1 %% n = tri; %% x = rand(1, n); %% y = rand(size(x)); %% tri = delaunay(x, y); %%end %% %%if nargin < 3 %% %% feval(mfilename, tri, x, y); %% %% set(gcf, 'Name', [upper(mfilename) ' Demo']) %% figure(gcf) %% %% return %% %%end %% %%isZero = (min(tri(:)) == 0); %% %%t = [tri(:, 1:2); tri(:, 2:3); tri(:, 3:-2:1)]; %% %%tt = t.'; %%if isZero %% tt = tt + 1; %%end %% %%x = x(:).'; %%y = y(:).'; %% %%xx = x(tt); %%yy = y(tt); %% %%if nargin < 4 %% h = plot(xx, yy, 'b-'); %%else %% h = plot3(xx, yy, 'b-', varargin{:}); %%end %% %%k = 1:length(x); %%if isZero %% k = k - 1; %%end %% %%label = cell(size(x)); %%for i = 1:length(x) %% index = k(i); %% label{i} = int2str(index); %%end %% %%text(x, y, label, 'Color', 'k', ... %% 'HorizontalAlignment', 'center', ... %% 'VerticalAlignment', 'middle', ... %% 'FontWeight', 'bold', 'FontSize', 12); %% %%t = tri.'; %%if isZero, t = t + 1; end %% %%xx = mean(x(t)); %%yy = mean(y(t)); %% %%[m, n] = size(tri); %%k = 1:m; %%if isZero, k = k - 1; end %% %%label = cell(size(xx)); %%for i = 1:length(k) %% index = k(i); %% label{i} = int2str(index); %%end %% %%text(xx, yy, label, 'Color', 'r', ... %% 'HorizontalAlignment', 'center', ... %% 'VerticalAlignment', 'middle', ... %% 'FontWeight', 'bold', 'FontSize', 12); %% %%if nargout > 0, theHandle = h; end %fclose(fout); % %disp(' ## Installing: "tripoly.m" (text)') %fout = fopen('tripoly.m', 'w'); %%function [tout, xout, yout, ind] = tripoly(x, y, doPlot) %% %%% tripoly -- Triangulation of a polygon. %%% [tout, xout, yout, ind] = tripoly(x, y, doPlot) modifies polygon %%% points (x, y), such that its triangulation tout consists solely %%% of strictly interior and exterior triangles, identifiable by their %%% counter-clockwise or clockwise sense, respectively. Use the %%% "trisense" function to distinguish between them. The returned %%% ind vector contains indices for reconstructing the original %%% polygon, using x = xout(ind) and y = yout(ind). Points not %%% listed in ind are "fake", i.e. added to achieve the goal of %%% this routine. %%% tripoly(nVertices, doPlot) demonstrates itself with nVertices %%% (random). Clicking on any triangle invokes the demonstration %%% again with different data. The "fake" points are marked by %%% a solid symbol. The plot is zoomable via "zoomsafe". %% %%% Copyright (C) 1999 Dr. Charles R. Denham, ZYDECO. %%% All Rights Reserved. %%% Disclosure without explicit written consent from the %%% copyright owner does not constitute publication. %% %%% Version of 07-Jul-1999 09:15:01. %%% Updated 30-Apr-2003 09:43:28. %% %%% The following URL describes the interesting Seidel's %%% Algorithm, not used here, in which the polygon is %%% decomposed first into trapezoids, and then into %%% "monotone" polygons, which are triangulated: %%% %% %%if nargin < 1, help(mfilename), x = 'demo'; end %%if isequal(x, 'demo'), x = 32; end %%if ischar(x), x = eval(x); end %% %%if nargin < 3, doPlot = 0; end %% %%if length(x) == 1 %% if nargin > 1 %% doPlot = y; %% elseif nargout < 1 %% doPlot = 1; %% else %% doPlot = 0; %% end %% nVertices = x; %% scale = nVertices^(1/3); %% rad = 1 + rand(nVertices, 1) / scale; %% ang = sort(rand(size(rad)) * 2 * pi); %% xy = rad .* exp(ang*sqrt(-1)); %% x = real(xy); y = imag(xy); %%end %% %%xi = x(:); yi = y(:); %%[zi, indices] = uniq([xi yi]); %%xi = zi(:, 1); yi = zi(:, 2); %% %%if length(xi) ~= length(x) %% warning(' ## Some data were culled because of non-uniqueness.') %%end %% %%% Make the polygon counter-clockwise. %%% Perhaps this step should not be done. %% %%if (0) %% if areaxy(xi, yi) < 0 %% xi = flipud(xi); %% yi = flipud(yi); %% end %%end %% %%% Algorithm: after triangulating the (x, y) points, %%% search for polygon edges that do not appear in %%% the triangulation itself. Bisect those orphaned %%% edges, re-triangulate, then test again, iterating %%% until no such edges remain. This scheme will %%% converge so long as the poly-line does not intersect %%% itself. %% %%% Eventually, we will stamp out the supplemental points, %%% ideally producing a triangularization from the original %%% points alone. This will be done by combining adjacent %%% triangles into a larger one where possible. Where not, %%% we will flip diagonals in existing quadralaterals, thereby %%% eliminating all edges that refer to one or more supplemental %%% points. Those points can then be deleted. %% %%% disp(' ') %% %%% tic %% %%added = zeros(length(xi), 1); %% %%orphans = 1; %% %%iteration = 0; %%while any(orphans) %% iteration = iteration + 1; %% tri = delaunay(xi, yi); %% tri = sort(tri.').'; %% edges = [tri(:, [1 2]); tri(:, [1 3]); tri(:, [2 3]); [length(xi) length(xi)]]; %% s = sparse(edges(:, 1), edges(:, 2), ones(size(edges(:,1)))); %% orphans = zeros(1, length(xi)); %% k = [1:length(xi) 1]; %% len = length(k); %% for i = len:-1:2 %% if i == len %% found = s(k(i), k(i-1)); %% else %% found = s(k(i-1), k(i)); %% end %% orphans(k(i-1)) = ~found; %% end %% %% f = find(orphans); %% if any(f) %% added(end+1) = 0; %% added = [added ones(size(added))].'; %% k = 1:length(xi)+1; %% ki = zeros(2, length(xi)+1); %% ki(1, :) = 1:length(xi)+1; %% ki(2, f) = f+0.5; %%% added = added(logical(ki)); %% added = added(~~ki); %% added = added(:); %% added(end) = []; %%% ki = ki(logical(ki)); %% ki = ki(~~ki); %% xtemp = xi(:); xtemp(end+1) = xi(1); %% ytemp = yi(:); ytemp(end+1) = yi(1); %% xi = interp1(k, xtemp, ki, '*linear'); %% yi = interp1(k, ytemp, ki, '*linear'); %% xi(end) = []; %% yi(end) = []; %% xi = xi(:); %% yi = yi(:); %% end %% %% if any(orphans) & rem(iteration, 10) == 0 %% disp([' ## ' mfilename ': orphans: ' int2str(sum(orphans))... %% '; length: ' int2str(length(xi))]); %% end %%end %% %%tri = trisort(tri); %% %%% To polish the solution, traverse around the original polygon, %%% seeking each "added" point in turn. If its geometry is %%% "simple", then the two adjacent interior triangles can be %%% squeezed together. Iterate until no such situations remain. %%% If we are lucky, the interior will thereby become devoid %%% of added triangles. %% %%% disp([' ## Elapsed time: ' num2str(toc) ' seconds.']) %% %%if nargout > 0 %% tout = tri; xout = xi; yout = yi; ind = find(~added); %%end %% %%if ~doPlot, return, end %% %%disp([' ## Added ' int2str(sum(~~added)) ' points.']) %% %%red = [1 0 0]; %%green = [0 1 0]; %%blue = [0 0 1]; %%white = red + green + blue; %%black = 0*white; %% %%delete(get(gca, 'Children')) %%hold off %%h = tripatch(tri, xi, yi); %%theBDF = [mfilename ' ' int2str(length(x))]; %%set(h(~isnan(h)), 'ButtonDownFcn', theBDF, 'EdgeColor', white) %%hold on %%f = find(added); %%plot(xi(f), yi(f), 'k+', 'MarkerFaceColor', 'k'); %%hold off %%view(2) %%title(theBDF) %%set(gca, 'XLim', [-2 2], 'YLim', [-2 2]) %%figure(gcf) %%zoomsafe %% %%if (0) %% %%theSense = trisense(tri, xi, yi); %%[m, n] = size(tri); %% %%delete(get(gca, 'Children')) %%hold off %% %%red = [1 0 0]; %%green = [0 1 0]; %%blue = [0 0 1]; %%white = red + green + blue; %%black = 0*white; %% %%for i = 1:m %% switch theSense(i) %% case -1 %% theColor = red; %% otherwise %% theColor = green; %% end %% h(i) = patch(xi(tri(i, :)), yi(tri(i, :)), theColor); %% hold on %%end %% %%theBDF = [mfilename ' ' int2str(length(x))]; %%set(h(~isnan(h)), 'ButtonDownFcn', theBDF, 'EdgeColor', white) %%f = find(added); %%h = plot(xi(f), yi(f), 'ko', 'MarkerFaceColor', 'k'); %%set(h, 'LineWidth', 1.5) %%f = find(~added); %%f(end+1) = 1; %%h = plot(xi(f), yi(f), '-ko'); %%set(h, 'LineWidth', 1.5) %%hold off %%view(2) %%title(theBDF) %%set(gca, 'XLim', [-2 2], 'YLim', [-2 2]) %%figure(gcf) %%zoomsafe %% %%end %fclose(fout); % %disp(' ## Installing: "trisense.m" (text)') %fout = fopen('trisense.m', 'w'); %%function theResult = trisense(tri, x, y) %% %%% trisense -- Sense of index rotation for triangles. %%% trisense(tri, x, y) returns +1 for the counter- %%% clockwise triangles of tri, and -1 for the %%% clockwise ones. The data are (x, y). %%% trisense('demo') demonstrates itself. %% %%% Copyright (C) 1999 Dr. Charles R. Denham, ZYDECO. %%% All Rights Reserved. %%% Disclosure without explicit written consent from the %%% copyright owner does not constitute publication. %% %%% Version of 29-Apr-1999 08:05:16. %%% Updated 12-Jul-1999 08:33:28. %% %%warning off MATLAB:convhull:ObsoleteThirdArgument %% %%if nargin < 1, help(mfilename), tri = 'demo'; end %%if isequal(tri, 'demo'), tri = 10; end %%if isstr(tri), tri = eval(tri); end %% %%if length(tri) == 1 %% npoints = tri; %% rad = 1 + rand(npoints, 1); %% ang = sort(rand(size(rad)) * 2 * pi); %% xy = rad .* exp(ang*sqrt(-1)); %% x = real(xy); y = imag(xy); %% tri = delaunay(x, y); %% hull = convhull(x, y, tri); %% tri = trisort(tri); %% s = trisense(tri, x, y); %% hold off %% i = s < 0; %% theColor = [1 0 0]; %% z = zeros(size(x)); %% for k = 1:2 %% if any(i) %% h = trimesh(tri(i, :), x, y, z, 'Tag', mfilename); %% set(h, 'FaceColor', theColor) %% hold on %% end %% i = s > 0; %% theColor = [0 1 0]; %% end %% theButtonDownFcn = ['trisense ' int2str(npoints)]; %% h = findobj(gcf, 'Tag', mfilename); %% set(h, 'ButtonDownFcn', theButtonDownFcn) %% x(end+1) = x(1); %% y(end+1) = y(1); %% plot(x, y, '-', 'LineWidth', 2.5) %% plot(x(hull), y(hull), 'o', 'MarkerSize', 10) %% hold off %% view(2) %% title(theButtonDownFcn) %% set(gcf, 'Name', 'TriSense Demo') %% zoomsafe %% figure(gcf) %% return %%end %% %%[m, n] = size(tri); %%if n == 1, tri = tri.'; end %% %%t = tri(:, [1 2 3 1]); %% %%x = x(t); %%y = y(t); %% %%[m, n] = size(x); %%if n == 1, x = x.'; y = y.'; end %% %%areas = 0.5 .* (x(:, 1:3).*y(:, 2:4) - x(:, 2:4).*y(:, 1:3)) * ones(3, 1); %% %%result = sign(areas); %% %%if nargout > 0 %% theResult = result; %%else %% disp(result) %%end %fclose(fout); % %disp(' ## Installing: "trisort.m" (text)') %fout = fopen('trisort.m', 'w'); %%function theResult = trisort(tri) %% %%% trisort -- Sort a triangular tessellation. %%% trisort(tri) sorts the indices of tri, %%% a triangular tessellation such as from %%% the "delaunay" function. The rows are %%% sorted and then arranged in order of %%% ascending first index. %% %%% Copyright (C) 1999 Dr. Charles R. Denham, ZYDECO. %%% All Rights Reserved. %%% Disclosure without explicit written consent from the %%% copyright owner does not constitute publication. %% %%% Version of 29-Apr-1999 08:00:44. %% %%if nargin < 1, help(mfilename), return, end %% %%result = sort(tri.').'; %%for j = 3:-1:1 %% [ignore, indices] = sort(result(:, j)); %% result = result(indices, :); %%end %% %%if nargout > 0 %% theResult = result; %%else %% disp(result) %%end %fclose(fout); % %disp(' ## Installing: "triterp.m" (text)') %fout = fopen('triterp.m', 'w'); %%function theResult = triterp(tri, x, y, z, xi, yi) %% %%% triterp -- Linear interpolation on triangles. %%% triterp(tri, x, y, z, xi, yi) interpolates z(x, y) %%% at points (xi, yi), using the triangulation %%% tri. If tri is empty, the Matlab "delaunay" %%% routine is called to compute it. %%% triterp(x, y, z, xi, yi) calls triterp([], x, y, z, xi, yi). %% %%% This routine is cloned directly from the "linear" %%% sub-function found in "griddata.m". %% %%% Modified blocks below are marked by "ZYDECO": %%% Copyright (C) 1999 Dr. Charles R. Denham, ZYDECO. %%% All Rights Reserved. %%% Disclosure without explicit written consent from the %%% copyright owner does not constitute publication. %% %%% Version of 25-Jun-1999 09:29:57. %%% Updated 30-Apr-2003 10:30:16. %% %%%function zi = linear(x,y,z,xi,yi) %%%LINEAR Triangle-based linear interpolation %% %%% Reference: David F. Watson, "Contouring: A guide %%% to the analysis and display of spacial data", Pergamon, 1994. %% %%warning off MATLAB:delaunay:ObsoleteThirdArgument %% %%if nargin < 5 | nargin > 6 % ZYDECO. %% help(mfilename) %% if nargout > 0, theResult = []; end %% return %%end %% %%if nargin < 5 | nargin > 6 % ZYDECO. %% error(' ## Requires exactly five or six input arguments.') %%end %% %%% Prepare for unavailable tri. %% %%if nargin == 5 % ZYDECO. %% yi = xi; %% xi = z; %% z = y; %% y = x; %% x = tri; %% tri = []; %% zi = triterp(tri, x, y, z, xi, yi); %% return %%end %% %%% Pad z with NaNs if shorter than the (x, y) data. %% %%if length(z) < length(x) % ZYDECO. %% z(length(x)) = 0; %% z(length(x)+1:end) = NaN; %%end %% %%siz = size(xi); %%xi = xi(:); yi = yi(:); % Treat these as columns %%x = x(:); y = y(:); % Treat these as columns %% %%% Triangularize the data %% %%if isempty(tri) % ZYDECO. %% tri = delaunay(x, y, 'sorted'); %%end %% %%if isempty(tri), %% warning('Data cannot be triangulated.'); %% zi = repmat(NaN, size(xi)); %% return %%end %% %%% Find the nearest triangle (t). %% %%v = version; %%if eval(v(1)) >= 6 %% t = tsearch(x, y, tri, xi, yi); %%else %% t = tsearchsafe(x, y, tri, xi, yi); % ZYCEDO. %%end %% %%% Only keep the relevant triangles. %% %%out = find(isnan(t)); %%if ~isempty(out), t(out) = ones(size(out)); end %%tri = tri(t,:); %% %%% Compute Barycentric coordinates (w). P. 78 in Watson. %% %%del = (x(tri(:,2))-x(tri(:,1))) .* (y(tri(:,3))-y(tri(:,1))) - ... %% (x(tri(:,3))-x(tri(:,1))) .* (y(tri(:,2))-y(tri(:,1))); %%w(:,3) = ((x(tri(:,1))-xi).*(y(tri(:,2))-yi) - ... %% (x(tri(:,2))-xi).*(y(tri(:,1))-yi)) ./ del; %%w(:,2) = ((x(tri(:,3))-xi).*(y(tri(:,1))-yi) - ... %% (x(tri(:,1))-xi).*(y(tri(:,3))-yi)) ./ del; %%w(:,1) = ((x(tri(:,2))-xi).*(y(tri(:,3))-yi) - ... %% (x(tri(:,3))-xi).*(y(tri(:,2))-yi)) ./ del; %%w(out,:) = zeros(length(out),3); %% %%z = z(:).'; % Treat z as a row so that code below involving %% % z(tri) works even when tri is 1-by-3. %% %%zi = sum(z(tri) .* w, 2); %% %%zi = reshape(zi, siz); %% %%if ~isempty(out), zi(out) = NaN; end %% %%if nargout > 0 %% theResult = zi; %%end %fclose(fout); % %disp(' ## Installing: "uniq.m" (text)') %fout = fopen('uniq.m', 'w'); %%function [theResult, indices] = uniq(x) %% %%% uniq -- Delete duplicated rows in matrix. %%% uniq(x) deletes duplicated rows from matrix x. %%% Unlike the Matlab "unique" routine, the present %%% function does not rearrange the order of rows. %%% [y, indices] = unique(x) also returns indices %%% such that y = x(indices, :). %% %%% Copyright (C) 1999 Dr. Charles R. Denham, ZYDECO. %%% All Rights Reserved. %%% Disclosure without explicit written consent from the %%% copyright owner does not constitute publication. %% %%% Version of 05-May-1999 09:59:50. %%% Updated 20-Jul-1999 11:04:23. %% %%[m, n] = size(x); %%oldm = m; %%if oldm == 1, x = x.'; end %%[m, n] = size(x); %% %%xout = x; %% %%indices = (1:m).'; %%for j = n:-1:1 %% [ignore, ind] = sort(x(:, j)); %% x = x(ind, :); %% indices = indices(ind); %%end %% %%d = diff(x); %% %%if n == 1 %% f = find(d == 0); %%else %% f = find(all(d.' == 0).'); %%end %% %%if any(f) %% indices(f+1) = []; %% indices = sort(indices); %% xout = xout(indices, :); %%end %% %%if oldm == 1, xout = xout.'; end %% %%if nargout > 0 %% theResult = xout; %%else %% disp(xout) %%end %fclose(fout); % %disp(' ## Installing: "zoomsafe.m" (text)') %fout = fopen('zoomsafe.m', 'w'); %%function theResult = zoomsafe(varargin) %% %%% zoomsafe -- Safe zooming with the mouse. %%% zoomsafe('demo') demonstrates itself with an interactive %%% line. Zooming occurs with clicks that are NOT on the line. %%% zoomsafe('on') initiates safe-zooming in the current window. %%% Zooming occurs with each click in the current-figure, except %%% on a graphical object whose "ButtonDownFcn" is active. %%% zoomsafe('on', 'all') applies any new axis limits to all the %%% axes in the figure. For companion axes having exactly the %%% same 'XLim' range as the one that was clicked, the 'YLim' %%% range remains intact. The same synchronization is invoked %%% for corresponding 'YLim' situations as well. %%% zoomsafe('all') same as zoomsafe('on', 'all'). %%% zoomsafe (no argument) same as zoomsafe('on'). %%% zoomsafe('off') turns it off. %%% zoomsafe('out') zooms fully out. %%% zoomsafe(theAmount, theDirection) applies theAmount of zooming %%% to theDirection: 'x', 'y', or 'xy' (default). %%% Note: when zooming actually occurs, this routine returns %%% logical(1); otherwise, logical(0). %%% %%% "Click-Mode" (Macintosh Action) Result %%% "normal" (click) Zoom out x2, centered on click. %%% "extend" (shift-click) Zoom in x2, centered on click. %%% "alt" (option-click) Center on click without zooming. %%% "open" (double-click) Revert to unzoomed state. %%% (Use click-down-and-drag to invoke a rubber-rectangle.) %%% %%% Use click-drag to map the zooming to a rubber-rectangle. %% %%% Copyright (C) 1997 Dr. Charles R. Denham, ZYDECO. %%% All Rights Reserved. %%% Disclosure without explicit written consent from the %%% copyright owner does not constitute publication. %% %%% Version of 19-Jun-1997 08:42:57. %%% Updated 02-Aug-1999 14:40:31. %% %%result = logical(0); %% %%if nargin < 1, varargin = {'on'}; end %% %%if isstr(varargin{1}) & ~isempty(varargin{1}) & ... %% any(varargin{1}(1) == '0123456789.') %% varargin{1} = eval(varargin{1}); %%end %% %%if ~isstr(varargin{1}) %% theAmount = varargin{1}; %% varargin{1} = 'manual'; %%end %% %%theFlag = logical(0); %%isAll = logical(0); %% %%theOldXLim = get(gca, 'XLim'); %%theOldYLim = get(gca, 'YLim'); %% %%switch varargin{1} %%case 'manual' %% isAll = (nargin > 2); %% theDirection = 'xy'; %% if nargin > 1, theDirection = varargin{2}; end %% theXLim = get(gca, 'XLim'); %% theYLim = get(gca, 'YLim'); %% if theAmount == 0 %% axis tight %% switch theDirection %% case 'x' %% set(gca, 'YLim', theYLim) %% case 'y' %% set(gca, 'XLim', theXLim) %% case 'xy' %% otherwise %% end %% theAmount = 1; %% theXLim = get(gca, 'XLim'); %% theYLim = get(gca, 'YLim'); %% end %% cx = mean(theXLim); %% cy = mean(theYLim); %% dx = diff(theXLim) ./ 2; %% dy = diff(theYLim) ./ 2; %% switch theDirection %% case 'x' %% theXLim = cx + [-dx dx] ./ theAmount; %% case 'y' %% theYLim = cy + [-dy dy] ./ theAmount; %% case 'xy' %% theXLim = cx + [-dx dx] ./ theAmount; %% theYLim = cy + [-dy dy] ./ theAmount; %% otherwise %% end %% set(gca, 'XLim', theXLim, 'YLim', theYLim); %% theFlag = 1; %%case 'demo' %% x = (0:30) ./ 30; %% y = rand(size(x)) - 0.5; %% for i = 2:-1:1 %% subplot(1, 2, i) %% theLine = plot(x, y, '-o'); %% set(theLine, 'ButtonDownFcn', 'disp(''## hello'')') %% set(gcf, 'Name', 'zoomsafe Demo') %% end %% result = zoomsafe('on', 'all'); %%case 'all' %% result = zoomsafe('on', 'all'); %%case 'on' %% isAll = (nargin > 1); %% if ~isAll %% set(gcf, 'WindowButtonDownFcn', 'if zoomsafe(''down''), end') %% else %% set(gcf, 'WindowButtonDownFcn', 'if zoomsafe(''down'', ''all''), end') %% end %%case 'down' %% isAll = (nargin > 1); %% dozoom = 0; %% switch get(gcbo, 'Type') %% case {'figure'} % "axes" not needed. %% switch switchsafe(get(gco, 'Type')) %% case {'figure'} %% dozoom = 1; %% otherwise %% if isempty(get(gco, 'ButtonDownFcn')) %% dozoom = 1; %% end %% end %% otherwise %% end %% switch dozoom %% case 1 %% thePointer = get(gcf, 'Pointer'); %% set(gcf, 'Pointer', 'watch') %% theRBRect = rbrect; %% x = sort(theRBRect([1 3])); %% y = sort(theRBRect([2 4])); %% theXLim = get(gca, 'XLim'); %% theYLim = get(gca, 'YLim'); %% theLimRect = [theXLim(1) theYLim(1) theXLim(2) theYLim(2)]; %% d = doubleclick; % Trap any double-click. %% if any(d) % Valid double-click. %% if ~isAll %% result = zoomsafe('out'); %% else %% result = zoomsafe('out', 'all'); %% end %% set(gcf, 'Pointer', 'arrow') %% if nargout > 0, theResult = result; end %% return %% elseif isempty(d) % Ignore initial-click of double. %% if nargout > 0, theResult = result; end %% return %% else % Not a double-click. %% end %% switch get(gcf, 'SelectionType') %% case 'normal' %% theFlag = 1; %% theAmount = [2 2]; % Zoom-in by factor of 2. %% case 'extend' %% theFlag = 1; %% theAmount = [0.5 0.5]; %% case 'open' % Pre-empted by "doubleclick" above. %% if ~isAll %% result = zoomsafe('out'); %% else %% result = zoomsafe('out', 'all'); %% end %% set(gcf, 'Pointer', 'arrow') %% if nargout > 0, theResult = result; end %% return %% otherwise %% theAmount = [1 1]; %% x = [mean(x) mean(x)]; %% y = [mean(y) mean(y)]; %% end %% if diff(x) == 0 | diff(y) == 0 %% cx = mean(x); %% cy = mean(y); %% dx = diff(theXLim) ./ 2; %% dy = diff(theYLim) ./ 2; %% x = cx + [-dx dx] ./ theAmount(1); %% y = cy + [-dy dy] ./ theAmount(2); %% else %% r1 = theLimRect; %% r2 = theRBRect; %% switch get(gcf, 'SelectionType') %% case 'normal' %% r4 = maprect(r1, r2, r1); %% case 'extend' %% r4 = maprect(r2, r1, r1); %% otherwise %% r4 = r1; %% end %% x = r4([1 3]); %% y = r4([2 4]); %% end %% set(gca, 'XLim', sort(x), 'YLim', sort(y)) %% theFlag = 1; %% result = logical(1); %% switch thePointer %% case {'watch', 'circle'} %% thePointer = 'arrow'; %% otherwise %% end %% set(gcf, 'Pointer', thePointer) %% set(gcf, 'Pointer', 'arrow') %% otherwise %% end %%case 'motion' %%case 'up' %%case 'off' %% set(gcf, 'WindowButtonDownFcn', ''); %%case 'out' %% isAll = (nargin > 1); %% theFlag = 1; %% axis tight %% result = logical(1); %%otherwise %% temp = eval(varargin{1}); %% switch class(temp) %% case 'double' %% if ~isAll %% result = zoomsafe(temp); %% else %% result = zoomsafe(temp, 'all'); %% end %% otherwise %% warning('## Unknown option') %% end %%end %% %%% Synchronize the other axes. %% %%if isAll & theFlag & 1 %% theGCA = gca; %% theXLim = get(theGCA, 'XLim'); %% theYLim = get(theGCA, 'YLim'); %% theAxes = findobj(gcf, 'Type', 'axes'); %% for i = 1:length(theAxes) %% if theAxes(i) ~= theGCA %% axes(theAxes(i)) %% x = get(gca, 'XLim'); %% y = get(gca, 'YLim'); %% if all(x == theOldXLim) %% set(theAxes(i), 'XLim', theXLim) %% end %% if all(y == theOldYLim) %% set(theAxes(i), 'YLim', theYLim) %% end %% end %% end %% axes(theGCA) %%end %% %%if nargout > 0, theResult = result; end %% %%% legend % Causes excessive flashing. %% %%function theResult = rbrect(onMouseUp, onMouseMove, onMouseDown) %% %%% rbrect -- Rubber rectangle tracking (Matlab-4 and Matlab-5). %%% rbrect('demo') demonstrates itself. %%% rbrect('onMouseUp', 'onMouseMove', 'onMouseDown') conducts interactive %%% rubber-rectangle tracking, presumably because of a mouse button press %%% on the current-callback-object (gcbo). The 'on...' callbacks are %%% automatically invoked with: "feval(theCallback, theInitiator, theRect)" %%% after each window-button event, using the object that started this %%% process, plus theRect as [xStart yStart xEnd yEnd] for the current %%% rubber-rect. The callbacks default to ''. The coordinates of the %%% rectangle are returned as [xStart yStart xEnd yEnd]. %% %%% Private interface: %%% rbrect(1) is automatically called on window-button-motions. %%% rbrect(2) is automatically called on window-button-up. %% %%% Copyright (C) 1997 Dr. Charles R. Denham, ZYDECO. %%% All Rights Reserved. %%% Disclosure without explicit written consent from the %%% copyright owner does not constitute publication. %% %%% Version of 03-Jun-1997 15:54:39. %%% Version of 11-Jun-1997 15:17:22. %%% Version of 17-Jun-1997 16:52:46. %% %%global RBRECT_HANDLE %%global RBRECT_INITIATOR %%global RBRECT_ON_MOUSE_MOVE %% %%if nargin < 1, onMouseUp = 0; end %% %%if strcmp(onMouseUp, 'demo') %% help rbrect %% x = cumsum(rand(200, 1) - 0.45); %% y = cumsum(rand(200, 1) - 0.25); %% h = plot(x, y, '-r'); %% set(h, 'ButtonDownFcn', 'disp(rbrect)') %% figure(gcf), set(gcf, 'Name', 'RBRECT Demo') %% return %% elseif isstr(onMouseUp) %% theMode = 0; %% else %% theMode = onMouseUp; %% onMouseUp = ''; %%end %% %% %%if theMode == 0 % Mouse down. %% if nargin < 3, onMouseDown = ''; end %% if nargin < 2, onMouseMove = ''; end %% if nargin < 1, onMouseUp = ''; end %% theVersion = version; %% isVersion5 = (theVersion(1) == '5'); %% if isVersion5 %% theCurrentObject = 'gcbo'; %% else %% theCurrentObject = 'gco'; %% end %% RBRECT_INITIATOR = eval(theCurrentObject); %% switch get(RBRECT_INITIATOR, 'Type') %% case 'line' %% theColor = get(RBRECT_INITIATOR, 'Color'); %% otherwise %% theColor = 'black'; %% end %% RBRECT_ON_MOUSE_MOVE = onMouseMove; %% pt = mean(get(gca, 'CurrentPoint')); %% x = [pt(1) pt(1)]; y = [pt(2) pt(2)]; %% RBRECT_HANDLE = line(x, y, ... %% 'EraseMode', 'xor', ... %% 'LineStyle', '--', ... %% 'LineWidth', 2.5, ... %% 'Color', theColor, ... %% 'Marker', '+', 'MarkerSize', 13, ... %% 'UserData', 1); %% set(gcf, 'WindowButtonMotionFcn', 'rbrect(1);') %% set(gcf, 'WindowButtonUpFcn', 'rbrect(2);') %% theRBRect = [x(1) y(1) x(2) y(2)]; %% if ~isempty(onMouseDown) %% feval(onMouseDown, RBRECT_INITIATOR, theRBRect) %% end %% thePointer = get(gcf, 'Pointer'); %% set(gcf, 'Pointer', 'circle'); %% if isVersion5 & 0 % Disable for rbrect().. %% eval('waitfor(RBRECT_HANDLE, ''UserData'', [])') %% else %% set(RBRECT_HANDLE, 'Visible', 'off') % Invisible. %% eval('rbbox') % No "waitfor" in Matlab-4. %% end %% set(gcf, 'Pointer', thePointer); %% set(gcf, 'WindowButtonMotionFcn', '') %% set(gcf, 'WindowButtonUpFcn', '') %% x = get(RBRECT_HANDLE, 'XData'); %% y = get(RBRECT_HANDLE, 'YData'); %% delete(RBRECT_HANDLE) %% theRBRect = [x(1) y(1) x(2) y(2)]; % Scientific. %% if ~isempty(onMouseUp) %% feval(onMouseUp, RBRECT_INITIATOR, theRBRect) %% end %%elseif theMode == 1 % Mouse move. %% pt2 = mean(get(gca, 'CurrentPoint')); %% x = get(RBRECT_HANDLE, 'XData'); %% y = get(RBRECT_HANDLE, 'YData'); %% x(2) = pt2(1); y(2) = pt2(2); %% set(RBRECT_HANDLE, 'XData', x, 'YData', y) %% theRBRect = [x(1) y(1) x(2) y(2)]; %% if ~isempty(RBRECT_ON_MOUSE_MOVE) %% feval(RBRECT_ON_MOUSE_MOVE, RBRECT_INITIATOR, theRBRect) %% end %%elseif theMode == 2 % Mouse up. %% pt2 = mean(get(gca, 'CurrentPoint')); %% x = get(RBRECT_HANDLE, 'XData'); %% y = get(RBRECT_HANDLE, 'YData'); %% x(2) = pt2(1); y(2) = pt2(2); %% set(RBRECT_HANDLE, 'XData', x, 'YData', y, 'UserData', []) %%else %%end %% %%if nargout > 0, theResult = theRBRect; end %% %%function rect4 = maprect(rect1, rect2, rect3) %% %%% maprect -- Map rectangles. %%% maprect(rect1, rect2, rect3) returns the rectangle %%% that is to rect3 what rect1 is to rect2. Each %%% rectangle is given as [x1 y1 x2 y2]. %%% maprect('demo') demonstrates itself by showing %%% that maprect(r1, r2, r1) ==> r2. %% %%% Copyright (C) 1997 Dr. Charles R. Denham, ZYDECO. %%% All Rights Reserved. %%% Disclosure without explicit written consent from the %%% copyright owner does not constitute publication. %% %%% Version of 19-Jun-1997 08:33:39. %% %%if nargin < 1, help(mfilename), rect1 = 'demo'; end %% %%if strcmp(rect1, 'demo') %% rect1 = [0 0 3 3]; %% rect2 = [1 1 2 2]; %% rect3 = rect1; %% r4 = maprect(rect1, rect2, rect3); %% begets(mfilename, 3, rect1, rect2, rect3, r4) %% return %%end %% %%if nargin < 3, help(mfilename), return, end %% %%r4 = zeros(1, 4); %%i = [1 3]; %%for k = 1:2 %% r4(i) = polyval(polyfit(rect1(i), rect2(i), 1), rect3(i)); %% i = i + 1; %%end %% %%if nargout > 0 %% rect4 = r4; %% else %% disp(r4) %%end %% %%function theResult = doubleclick %% %%% doubleclick -- Trap for double-clicks. %%% doubleclick (no argument) returns TRUE if a click %%% is detected during its execution; otherwise, FALSE. %%% Call "doubleclick" during a "WindowButtonDown" or %%% "ButtonDown" callback, preferably at the top of %%% procedure. The 'Interruptible' property of the %%% callback-object must be 'on'. The double-click %%% time is 0.5 sec. A valid double-click causes %%% two values to be returned: first, a logical(1), %%% then an empty-matrix []. The latter signifies %%% the single-click that initiated the process. %%% For a valid single-click, only logical(0) is %%% returned. %% %%% Copyright (C) 1997 Dr. Charles R. Denham, ZYDECO. %%% All Rights Reserved. %%% Disclosure without explicit written consent from the %%% copyright owner does not constitute publication. %% %%% Version of 25-Jul-1998 09:47:16. %% %%global CLICK_COUNT %% %%DOUBLE_CLICK_TIME = 1/2; % Seconds. %% %%if isempty(CLICK_COUNT), CLICK_COUNT = 0; end %% %%CLICK_COUNT = CLICK_COUNT + 1; %% %%if CLICK_COUNT == 1 %% tic %% while isequal(CLICK_COUNT, 1) & toc < DOUBLE_CLICK_TIME, end %%end %% %%drawnow % Process the event-cue. %% %%% Note: %%% Despite the "drawnow" seen above, Matlab does not %%% update the "SelectionType" in timely fashion, so %%% it cannot be used to trap a double-click properly. %% %%result = (CLICK_COUNT > 1); %% %%CLICK_COUNT = []; %% %%if nargout > 0 %% theResult = result; %%else %% disp(result) %%end %fclose(fout); %cd ('..') %disp(' ') %disp(' ## Add the "tri" folder to your Matlab path.') %disp(' ## Execute "polyrand" at the Matlab prompt.') %disp(' ') fclose(fout); disp(' ## Installing: "tsearchsafe.m" (text)') fout = fopen('tsearchsafe.m', 'w'); %function theResult = tsearchsafe(x, y, tri, xi, yi) % %% tsearchsafe -- TSEARCH for arbitrary triangles. %% tsearchsafe('demo') demonstrates itself by %% invoking "tsearch(10)". %% tsearchsafe(NTRI, NPTS) demonstrates itself with %% NTRI triangles and NPTS test-points (defaults: %% NTRI=10, NPTS=10*NTRI). %% tsearchsafe(x, y, tri, xi, yi) mimics TSEARCH for %% an arbitrary group of non-overlapping triangles, %% not necessarily produced by DELAUNAY. The result %% is an array of triangle indices for those points %% that lie on or within at least one triangle. All %% other points are represented by NaN. For points %% lying on or within more than one triangle, only %% one such boundary is identified, as in TSEARCH. %% %% Note: This routine exists because TSEARCH itself %% is not reliable for non-Delaunay sets of triangles. % %% Copyright (C) 2000 Dr. Charles R. Denham, ZYDECO. %% All Rights Reserved. %% Disclosure without explicit written consent from the %% copyright owner does not constitute publication. % %% Version of 04-Apr-2000 15:24:36. %% Updated 08-Sep-2000 13:40:32. % %if nargout > 0, theResult = []; end % %if nargin < 1, help(mfilename), x = 'demo'; end % %if isequal(x, 'demo'), x = 10; end %if ischar(x), x = eval(x); end % %if length(x) == 1 % nTriangles = max(x, 5); % if nargin < 2, y = 10*x; end % if ischar(y), y = eval(y); end % nPoints = max(y, 10); % x = 0.75*rand(2*nTriangles, 1) + 1/8; % y = 0.75*rand(2*nTriangles, 1) + 1/8; % tri = delaunay(x, y); % [r, indices] = sort(rand(size(tri, 1), 1), 1); % tri = tri(indices(1:nTriangles), :); % xi = rand(nPoints, 1); % yi = rand(nPoints, 1); % tic; % result = feval(mfilename, x, y, tri, xi, yi); % disp([' ## Elapsed time: ' num2str(toc) ' s']) % if nargout > 0 % theResult = result; % else % theDefaultMarkerSize = get(0, 'DefaultLineMarkerSize'); % theDefaultLineWidth = get(0, 'DefaultLineLineWidth'); % theMarkerSize = theDefaultMarkerSize/sqrt(nPoints/1000); % theMarkerSize = min(theDefaultMarkerSize, ... % max(theDefaultLineWidth, theMarkerSize)); % f = find(~isnan(result)); % g = find(isnan(result)); % hold off % h = plot(xi(f), yi(f), 'g+', ... % xi(g), yi(g), 'r+', ... % 'MarkerSize', theMarkerSize); % hold on % trimesh(tri, x, y, zeros(size(x)), ... % 'EdgeColor', [0 0 1], ... % 'FaceColor', 'none', ... % 'LineWidth', 0.5) % hold off % view(2) % grid off % try, zoomsafe, catch, zoom on, end % figure(gcf) % set(gcf, 'Name', [mfilename ' ' int2str(nTriangles) ' ' int2str(nPoints)]) % if nargout > 0, theResult = result; end % end % return %end % %result = zeros(size(xi)) + NaN; % %% Compute bounding rectangles for triangles. % %t = tri.'; %xmin = min(x(tri.')).'; %xmax = max(x(tri.')).'; %ymin = min(y(tri.')).'; %ymax = max(y(tri.')).'; % %% Eliminate out-of-bounds points from %% further consideration. % %g = find(xi >= min(xmin) & xi <= max(xmax) & ... % yi >= min(ymin) & yi <= max(ymax)); % %if (0) % eliminated = length(xi) - length(g) %end % %% For each point, find all the triangles %% for which each point lies within their %% bounding rectangles, then perform TSEARCH %% on each one. We depend on the assumption %% that TSEARCH is reliable for a single %% triangle and many points. % %% NOTE: By pre-sorting the triangles and the (xi, yi) %% points, we could reduce the calculation time, by %% (say) working from right-to-left. %% Also, whereas we presently loop over the (xi, yi), %% we could also do the opposite, depending on the %% relative numbers of triangles and (xi, yi) points. % %for j = 1:length(g) % k = g(j); % xtemp = xi(k); % ytemp = yi(k); % f = find( ... % Points strictly inside the bounds. % (xtemp > xmin) & ... % (xtemp < xmax) & ... % (ytemp > ymin) & ... % (ytemp < ymax)); % if any(f) % for i = 1:length(f) % index = tsearch(x, y, tri(f(i), :), xtemp, ytemp); % if ~isnan(index) % result(k) = f(i); % end % end % end %end % %if nargout > 0 % theResult = result; %else % disp(result) %end fclose(fout); disp(' ## Installing: "uidefaults.m" (text)') fout = fopen('uidefaults.m', 'w'); %function theResult = uidefaults(theHandle, isFactory) % %% uidefaults -- Default settings for HandleGraphics entities. %% uidefaults(theHandle) displays or returns a structure containing %% the default values for all properties of theHandle. Properties %% that do not have a default value are marked by the string %% '(No such setting)'. Note: Some property names may be %% truncated by Matlab. TheHandle can be a UI type or nickname, %% such as 'figure' or 'gcf'. Default is 0, the root object. %% uidefaults(theHandle, isFactory) performs the same task %% for the "factory" settings of theHandle, if "isFactory" %% evaluates to true. % %% Copyright (C) 2002 Dr. Charles R. Denham, ZYDECO. %% All Rights Reserved. %% Disclosure without explicit written consent from the %% copyright owner does not constitute publication. % %% Version of 06-Mar-2002 16:04:55. %% Updated 22-Jan-2003 10:16:01. % %if nargout > 0, theResult = []; end %if nargin < 1, theHandle = 0; end %if nargin < 2, isFactory = ~~0; end %if ischar(isFactory), isFactory = eval(isFactory); end % %mode = 'Default'; %if isFactory, mode = 'Factory'; end % %NO_SUCH_SETTING = '(No such setting)'; %TOP_LABEL = [mode '_Settings_For']; %BOTTOM_LABEL = ['End_' mode '_Settings_For']; % %theTypes = {'axes', 'figure', 'image', 'light', 'line', ... % 'patch', 'rectangle', 'root', 'surface', 'text', ... % 'uicontextmenu', 'uicontrol', 'uimenu'}; % %% Get the existing figures, if any. % %theFigures = get(0, 'Children'); % %% Find or create an object of the particular type. % %didExist = ~~1; %if ischar(theHandle) % theType = lower(theHandle); % for i = 1:length(theTypes) % f = findstr(theTypes{i}, theType); % if any(f) & any(f == 1) % theType = theTypes{i}; % break % end % end % switch theType % case 'root' % theHandle = 0; % case {'gcf', 'gca', 'gco', 'gcbo', 'gcbf'} % theHandle = eval(theType); % otherwise % try % theHandle = findobj('Type', theType); % if any(theHandle) % theHandle = theHandle(1); % else % switch theType % case 'figure' % if ~any(theFigures) % Need temporary figure. % figure('Visible', 'off'); % Avoid flashing. % didExist = ~~0; % end % case {'axes', 'image', 'light', 'line', ... % 'patch', 'rectangle', 'surface', 'text', ... % 'uicontextmenu', 'uicontrol', 'uimenu'} % if ~any(theFigures) % Need temporary figure. % figure('Visible', 'off'); % Avoid flashing. % end % theHandle = feval(theType); % didExist = ~~0; % otherwise % error(' ## No such HandleGraphics type.') % end % end % catch % disp([' ## No such HandleGraphics type: "' theType '"']) % return % end % end %end % %if isempty(theHandle) % disp(' ## Handle is empty.') % return %end % %% Make undocumented properties visible. % %theUndocState = get(0, 'HideUndocumented'); %set(0, 'HideUndocumented', 'off') % %% Gather all possible property names. % %theType = get(theHandle, 'Type'); %switch lower(theType(1)) %case 'u' % theType(1:3) = upper(theType(1:3)); %otherwise % theType(1) = upper(theType(1)); %end % %theWarningState = warning; %warning off % %theGettables = get(theHandle); %theSettables = set(theHandle); %theFieldnames = [fieldnames(theSettables); fieldnames(theGettables)]; % %% Delete the object if created here. % %if ~didExist % f = find(theFigures == get(0, 'CurrentFigure')); % if ~any(f) % delete(gcf) % Delete whole window. % else % delete(theHandle) % end %end % %% Cull duplicated names. % %theFieldnames = sort(theFieldnames); %for i = length(theFieldnames):-1:2 % if isequal(theFieldnames(i), theFieldnames(i-1)) % theFieldnames(i) = []; % end %end % %% Get the default properties from the root object. % %result = []; %result = setfield(result, TOP_LABEL, lower(theType)); % %for i = 1:length(theFieldnames) % s = [mode theType theFieldnames{i}]; % try % x = get(0, s); % catch % x = NO_SUCH_SETTING; % end % s = [theFieldnames{i}]; % while s(1) == '_' % Some names begin with '_'. % s(1) = ''; % s = [s '_']; % end % result = setfield(result, s, x); %end % %warning(theWarningState) % %result = setfield(result, BOTTOM_LABEL, lower(theType)); % %% Restore visibility of undocumented properties. % %set(0, 'HideUndocumented', theUndocState) % %if nargout > 0 % theResult = result; %else % disp(result) %end fclose(fout); disp(' ## Installing: "uidelete.m" (text)') fout = fopen('uidelete.m', 'w'); %function uidelete % %% uidelete -- Delete files via dialog. %% uidelete (no argument) deletes one or more %% files selected with the "uigetfile" dialog. %% *** Not for the faint of heart. *** % %% Copyright (C) 1997 Dr. Charles R. Denham, ZYDECO. %% All Rights Reserved. %% Disclosure without explicit written consent from the %% copyright owner does not constitute publication. % %% Version of 19-Jun-1998 15:17:32. % %help(mfilename) % %oldPWD = pwd; % %thePrompt = 'Delete Which File?'; % %while (1) % [theFile, thePath] = uigetfile('*', thePrompt); % if ~any(theFile), return, end % if thePath(length(thePath)) ~= filesep % thePath = [thePath filesep]; % end % cd(thePath) % delete([thePath theFile]) % thePrompt = 'Delete Another File?'; %end % %cd(oldPWD) fclose(fout); disp(' ## Installing: "uilayout.m" (text)') fout = fopen('uilayout.m', 'w'); %function theResult = UILayout(theControls, theLayout, thePosition) % %% UILayout -- Layout for ui controls. %% UILayout(theControls, theLayout) positions theControls %% according to theLayout, an array whose entries, taken %% in sorted order, define the rectangular extents occupied %% by each control. TheLayout defaults to a simple vertical %% arrangement of theControls. A one-percent margin is %% imposed between controls. To define a layout region %% containing no control, use Inf. %% UILayout(..., thePosition) confines the controls to the %% given normalized position of the figure. This syntax %% is useful for embedding controls within a frame. %% UILayout (no argument) demonstrates itself. % %% Copyright (C) 1997 Dr. Charles R. Denham, ZYDECO. %% All Rights Reserved. %% Disclosure without explicit written consent from the %% copyright owner does not constitute publication. % %% Version of 18-Apr-1997 08:07:54. % %if nargin < 1, theControls = 'demo'; help(mfilename), end % %if strcmp(theControls, 'demo') % theLayout = [1 2; % 3 4; % 5 Inf; % 5 6; % 5 Inf; % 7 8; % 9 10; % 11 12; % 13 14]; % [m, n] = size(theLayout); % thePos = get(0, 'DefaultUIControlPosition'); % theSize = [n+2 m+2] .* thePos(3:4); % theFigure = figure('Name', 'UILayout', ... % 'NumberTitle', 'off', ... % 'Resize', 'off', ... % 'Units', 'pixels'); % thePos = get(theFigure, 'Position'); % theTop = thePos(2) + thePos(4); % thePos = thePos .* [1 1 0 0] + [0 0 theSize]; % thePos(2) = theTop - (thePos(2) + thePos(4)); % set(theFigure, 'Position', thePos); % theFrame = uicontrol('Style', 'frame', ... % 'Units', 'normalized', ... % 'Position', [0 0 1 1], ... % 'BackgroundColor', [0.5 1 1]); % theStyles = {'checkbox'; 'text'; ... % 'edit'; 'text'; ... % 'listbox'; 'text'; ... % 'popupmenu'; 'text'; ... % 'pushbutton'; 'text'; ... % 'radiobutton'; 'text'; ... % 'text'; 'text'}; % theStrings = {'Anchovies?', '<-- CheckBox --', ... % 'Hello World!', '<-- Edit --', ... % {'Now', 'Is', 'The' 'Time' 'For' 'All' 'Good', ... % 'Men', 'To', 'Come' 'To' 'The' 'Aid' 'Of', ... % 'Their' 'Country'}, ... % '<-- ListBox --', ... % {'Cheetah', 'Leopard', 'Lion', 'Tiger', 'Wildcat'}, ... % '<-- PopupMenu --', ... % 'Okay', '<-- PushButton --', ... % 'Cream?', '<-- RadioButton --', ... % 'UILayout', '<-- Text --'}; % theControls = zeros(size(theStyles)); % for i = 1:length(theStyles) % theControls(i) = uicontrol('Style', theStyles{i}, ... % 'String', theStrings{i}, ... % 'Callback', ... % 'disp(int2str(get(gcbo, ''Value'')))'); % end % set(theControls(1:2:length(theControls)), 'BackGroundColor', [1 1 0.5]) % set(theControls(2:2:length(theControls)), 'BackGroundColor', [0.5 1 1]) % thePosition = [1 1 98 98] ./ 100; % uilayout(theControls, theLayout, thePosition) % set(theFrame, 'UserData', theControls) % theStyles, theLayout, thePosition % if nargout > 0, theResult = theFrame; end % return %end % %if nargin < 2, theLayout = (1:length(theControls)).'; end %if nargin < 3, thePosition = [0 0 1 1]; end % %a = theLayout(:); %a = a(finite(a)); %a = sort(a); %a(diff(a) == 0) = []; % %b = zeros(size(theLayout)); % %for k = 1:length(a) % b(theLayout == a(k)) = k; %end % %[m, n] = size(theLayout); % %set(theControls, 'Units', 'Normalized') %theMargin = [1 1 -2 -2] ./ 100; %for k = 1:min(length(theControls), length(a)) % [i, j] = find(b == k); % xmin = (min(j) - 1) ./ n; % xmax = max(j) ./ n; % ymin = 1 - max(i) ./ m; % ymax = 1 - (min(i) - 1) ./ m; % thePos = [xmin ymin (xmax-xmin) (ymax-ymin)] + theMargin; %if (1) % thePos = thePos .* thePosition([3 4 3 4]); % thePos(1:2) = thePos(1:2) + thePosition(1:2); %end % set(theControls(k), 'Position', thePos); %end % %if nargout > 0, theResult = theControls; end fclose(fout); disp(' ## Installing: "undoc.m" (text)') fout = fopen('undoc.m', 'w'); %function theResult = undoc(theHandle) % %% undoc -- Undocumented properties of a handle. %% undoc(theHandle) returns or lists the names of the %% undocumented properties of theHandle (default = 0). %% Uses the "HideUndocumented" property of the %% root object (0). % %% Copyright (C) 1999 Dr. Charles R. Denham, ZYDECO. %% All Rights Reserved. %% Disclosure without explicit written consent from the %% copyright owner does not constitute publication. % %% Version of 20-Oct-1999 00:45:25. %% Updated 05-Mar-2003 10:17:05. % %if nargout > 0, theResult = {}; end %if nargin < 1, help(mfilename), theHandle = 0; end %if ischar(theHandle), theHandle = eval(theHandle); end % %if isempty(theHandle), return, end % %theWarningState = warning; %warning('off') % %theUndocState = get(0, 'hideundocumented'); % %set(0, 'hideundocumented', 'on') % %a = get(theHandle); % Documented properties. % %set(0, 'hideundocumented', 'off') % %b = get(theHandle); % All properties. % %set(0, 'hideundocumented', theUndocState) % Restore. % %warning(theWarningState) % Restore. % %theNames = fieldnames(b); % %for i = length(theNames):-1:1 % if isfield(a, theNames{i}) % theNames(i) = []; % end %end % %if nargout > 0 % theResult = theNames; %else % theType = get(theHandle, 'Type'); % disp([' ## Undocumented properties of "' theType '"']) % disp(theNames) %end fclose(fout); disp(' ## Installing: "unspar.m" (text)') fout = fopen('unspar.m', 'w'); %function y = unspar(x, realFlag) % %% unspar -- Convert "spar" array to "sparse". %% unspar(x) converts the "spar" array x %% to a Matlab "sparse" array, if the data %% represent a two-dimensional array; otherwise, %% to a "full" array. See "help spar". %% unspar(x, realFlag) assumes that x lacks the %% imaginary-component column, if realFlag is TRUE. %% NOTE: a complex-array will be auto-detected, so %% long as the next-to-last column contains values %% that would be invalid as indices. % %% Copyright (C) 1999 Dr. Charles R. Denham, ZYDECO. %% All Rights Reserved. %% Disclosure without explicit written consent from the %% copyright owner does not constitute publication. % %% Version of 19-Aug-1999 14:30:00. %% Updated 24-Aug-1999 11:34:47. % %if nargin < 1, help(mfilename), return, end %if nargin < 2, realFlag = 0; end % %[m, n] = size(x); % %if realFlag % valid_indices =... % isfinite(x(:, end-1)) & ... % (x(:, end-1) > 0) & ... % (x(:, end-1) == fix(x(:, end-1))); % if ~all(valid_indices), realFlag = 0; end %end % %if ~realFlag % dim = n-2; %else % dim = n-1; %end % %siz = zeros(1, dim); %sub = cell(1, dim); %for j = 1:dim % dat = x(:, j); % siz(j) = max(dat); % sub{j} = dat; %end %ind = sub2ind(siz, sub{:}); % %if dim == 2 % if ~realFlag % result = sparse(sub{1}, sub{2}, x(:, end-1) + sqrt(-1) * x(:, end)); % else % result = sparse(sub{1}, sub{2}, x(:, end)); % end %else % result = zeros(siz); % if ~realFlag % result(ind) = x(:, end-1) + sqrt(-1) * x(:, end); % else % result(ind) = x(:, end); % end %end % %if nargout > 0 % y = result; %else % disp(result) % assignin('caller', 'ans', result) %end fclose(fout); disp(' ## Installing: "vargstr.m" (text)') fout = fopen('vargstr.m', 'w'); %function theEvalString = VargStr(fcn, nvarargin, nvarargout) % %% VargStr -- Eval-string for varargin and varargout. %% VargStr('fcn', nvarargin, nvarargout) returns a string %% that calls the 'fcn' function when eval-ed. The input %% arguments are expressed as vargargin{...} and varargout{...}, %% respectively. If nvarargin or nvarargout is a cell-object, %% its length is used. The argument-counts default to zero. % %% Copyright (C) 1996 Dr. Charles R. Denham, ZYDECO. %% All Rights Reserved. %% Disclosure without written consent from the %% copyright owner does not constitute publication. % %if nargin < 1, help(mfilename), return, end % %if nargin < 2, nvarargin = 0; end %if nargin < 3, nvarargout = 0; end % %if isa(nvarargin, 'cell') % nvarargin = length(nvarargin); %end % %if isa(nvarargout, 'cell') % nvarargout = length(nvarargout); %end % %s = ''; % %if nvarargout > 0 % s = [s '[']; % for i = 1:nvarargout % if i > 1, s = [s ',']; end % s = [s 'varargout{' int2str(i) '}']; % end % s = [s ']']; %end % %if ~isempty(fcn) % if nvarargout > 0, s = [s '=']; end % s = [s fcn]; %end % %if nvarargin > 0 % s = [s '(']; % for i = 1:nvarargin % if i > 1, s = [s ',']; end % s = [s 'varargin{' int2str(i) '}']; % end % s = [s ')']; %end % %if ~isempty(fcn), s = [s ';']; end % %if nargout > 0 % theEvalString = s; % else % disp(s) %end fclose(fout); disp(' ## Installing: "vi.m" (text)') fout = fopen('vi.m', 'w'); %function vi(theFile) % %% vi -- Invoke "vi" on Unix. %% vi('theFile') invokes "vi" on 'theFile' in Unix. %% If 'theFile' is empty or a wildcard, the "uigetfile" %% dialog is activated to get the actual filename. If %% the OS is not Unix, "edit" is invoked. % %% Copyright (C) 1999 Dr. Charles R. Denham, ZYDECO. %% All Rights Reserved. %% Disclosure without explicit written consent from the %% copyright owner does not constitute publication. % %% Version of 01-Jun-1999 09:04:48. %% Updated 06-Mar-2000 10:50:08. % %if nargin < 1, theFile = '*'; end % %if any(theFile == '*') | isempty(theFile) % [f, p] = uigetfile(theFile); % if ~any(f), return, end % if p(end) ~= filesep, p(end+1) = filesep; end % theFile = [p f]; %end % %w = which(theFile); % %if any(w) % clear(w) % if isunix % eval(['!vi ' w]) % else % edit(w) % end %else % disp([' ## No such file: ' theFile]) %end fclose(fout); disp(' ## Installing: "which1s.m" (text)') fout = fopen('which1s.m', 'w'); %function theResult = which1s(theFunction) % %% which1s -- "which" for entire Matlab path. %% which1s('theFunction') performs "which" for %% all parts of the Matlab path, returning a %% list of instances of 'theFunction', the %% first of which is the current one. The %% routine ignores class-methods. %% which1s (no argument) demonstrates itself %% by operating on itself. %% %% Also see: which('theFunction', '-all'), %% a fast built-in function whose output %% differs somewhat from "which1s". % %% Copyright (C) 2000 Dr. Charles R. Denham, ZYDECO. %% All Rights Reserved. %% Disclosure without explicit written consent from the %% copyright owner does not constitute publication. % %% Version of 29-Mar-2000 09:31:12. %% Updated 29-Mar-2000 10:08:39. % %if nargin < 1& nargout < 1 % help(mfilename) % feval(mfilename, mfilename) % return %end % %current = which(theFunction); % %if isempty(current) % Not found. % w = {[theFunction ' not found.']}; %else % Find others. % p = path; % if p(1) ~= pathsep, p = [pathsep p]; end % if p(end) ~= pathsep, p(end+1) = pathsep; end % f = find(p == pathsep); % w = cell(length(f-1), 1); % w{1} = current; % theOldPWD = pwd; % for i = 2:length(f) % w{i} = ''; % theDir = p(f(i-1)+1:f(i)-1); % if ~isempty(theDir) % cd(theDir) % w{i} = which(theFunction); % end % end % cd(theOldPWD) %end % %% Delete duplicates. % %[w, indices] = sort(w); %for i = length(w):-1:2 % if isequal(w{i}, w{i-1}) % w{i} = ''; % end %end %w(indices) = w; % %for i = length(w):-1:2 % if isempty(w{i}) % w(i) = []; % end %end % %if nargout > 0 % theResult = w; %else % for i = 1:length(w) % disp(w{i}) % end %end fclose(fout); disp(' ## Installing: "whov.m" (text)') fout = fopen('whov.m', 'w'); %function theResult = whov(varargin) % %% whov -- WHOS + value. %% w = whov (no argument) returns a WHOS structure %% with an added "value" field for each item in %% the caller's workspace. %% whov(w) restores the values given in %% struct "w" to the caller's workspace. %% w = whov('matfilename') performs "whov" on %% the contents of the given mat-file. %% whov('matfilename', w) restores the values %% in struct "w" to the given mat-file, using %% the "-append" option of the "save" function. %% This is tricky, since "save" has no way to %% specify the name of an item separately from %% its value. % %% Copyright (C) 1998 Dr. Charles R. Denham, ZYDECO. %% All Rights Reserved. %% Disclosure without explicit written consent from the %% copyright owner does not constitute publication. % %% Version of 12-Aug-1998 19:07:07. %% Updated 21-Sep-2001 10:06:45. % %% Note: we append "---" to all the names, to avoid %% collisions when restoring values to a mat-file. % %if nargin < 1 % Save from caller. % w___ = evalin('caller', 'whos'); % if length(w___) > 0 % w___(end).value = []; % for i = 1:length(w___) % w___(i).value = evalin('caller', w___(i).name); % end % end %elseif nargin < 2 & ischar(varargin{1}) % Mat-file. % matfile___ = varargin{1}; % w___ = whos('-file', matfile___); % if length(w___) > 0 % v___ = load(matfile___); % for i = 1:length(w___) % w___(i).value = getfield(v___, w___(i).name); % end % end %elseif nargin < 2 % Restore to caller. % w___ = varargin{1}; % for i___ = 1:length(w___) % assignin('caller', w___(i___).name, w___(i___).value) % end %elseif nargin > 1 & ischar(varargin{1}) & isstruct(varargin{2}) % Matfile. % matfile___ = varargin{1}; % w___ = varargin{2}; % for i___ = 1:length(w___) % s___ = [w___(i___).name ' = w___(i___).value;']; % eval(s___); % save(matfile___, w___(i___).name, '-append') % end %end % %if nargout > 0 % theResult = w___; %end fclose(fout); disp(' ## Installing: "wigglex.m" (text)') fout = fopen('wigglex.m', 'w'); %function theResult = wigglex(x, y, z, varargin) % %% wigglex -- Wiggle-plot with variation in x. %% wigglex(x, y, z, ...) plots the columns of z(x, y) %% as vertical traces, with origins given by vector x. %% The "line" handles are returned if requested. %% Additional arguments are passed directly to "plot". %% The columns of z should be roughly zero-mean, with %% variances scaled according to the x intervals. %% wiggles(z, ...) plots z with x and y corresponding %% to the size of the z matrix. %% wiggles('demo') demonstrates itself. %% wiggles(m, n) demonstrates itself for a random z-array %% of size [m n] (default is [50 25]). % %% Copyright (C) 1998 Dr. Charles R. Denham, ZYDECO. %% All Rights Reserved. %% Disclosure without explicit written consent from the %% copyright owner does not constitute publication. % %% Version of 12-Sep-1998 06:22:41. % %if nargin < 1, x = 'demo'; end % %if isequal(x, 'demo'), x = 50; end % %if ischar(x), x = eval(x); end % %if length(x) == 1 % help(mfilename) % if nargin < 2, y = round(x/2); end % if ischar(y), y = eval(y); end % m = x; % n = y; % x = 1:n; % y = 1:m; % z = rand(m, n) - 0.5; % z = cumsum(z.').'; % s = std(z); % for j = 1:n % i = isfinite(z(:, j)); % if any(i) % scale = std(z(i, j)); % z(:, j) = z(:, j) ./ scale; % end % end % set(gcf, 'Name', 'WiggleX Demo') % wigglex(x, y, z, 'm') % set(gca, 'YDir', 'reverse') % axis tight % xlabel('Column #'), ylabel('Row #') % figure(gcf) % return %end % %if nargin == 1 | ischar(y) % if nargin > 1, varargin{1} = y; end % z = x; % [m, n] = size(z); % x = 1:n; % y = 1:m; %end % %x = x(:).'; % Row-vector. %y = y(:); % Column-vector. % %[m, n] = size(z); % %for j = 1:n % z(:, j) = z(:, j) + x(j); %end % %result = plot(z, y, varargin{:}); % %if nargout > 0, theResult = result; end fclose(fout); disp(' ## Installing: "wiggley.m" (text)') fout = fopen('wiggley.m', 'w'); %function theResult = wiggley(x, y, z, varargin) % %% wiggley -- Wiggle-plot with variation in x. %% wiggley(x, y, z, ...) plots the rows of z(x, y) %% as horizontal traces, with origins given by vector y. %% The "line" handles are returned if requested. %% Additional arguments are passed directly to "plot". %% The rows of z should be roughly zero-mean, with %% variances scaled according to the x intervals. %% wiggles(z, ...) plots z with x and y corresponding %% to the size of the z matrix. %% wiggles('demo') demonstrates itself. %% wiggles(m, n) demonstrates itself for a random z-array %% of size [m n] (default is [25 50]). % %% Copyright (C) 1998 Dr. Charles R. Denham, ZYDECO. %% All Rights Reserved. %% Disclosure without explicit written consent from the %% copyright owner does not constitute publication. % %% Version of 12-Sep-1998 06:22:41. % %if nargin < 1, x = 'demo'; end % %if isequal(x, 'demo'), x = 25; end % %if ischar(x), x = eval(x); end % %if length(x) == 1 % help(mfilename) % if nargin < 2, y = 2*x; end % if ischar(y), y = eval(y); end % m = x; % n = y; % x = 1:n; % y = 1:m; % z = rand(m, n) - 0.5; % z = cumsum(z); % s = std(z); % for i = 1:m % j = isfinite(z(i, :)); % if any(i) % scale = std(z(i, j)); % z(i, :) = z(i, :) ./ scale; % end % end % set(gcf, 'Name', 'WiggleY Demo') % wiggley(x, y, z, 'm') % set(gca, 'YDir', 'reverse') % axis tight % xlabel('Column #'), ylabel('Row #') % figure(gcf) % return %end % %if nargin == 1 | ischar(y) % if nargin > 1, varargin{1} = y; end % z = x; % [m, n] = size(z); % x = 1:n; % y = 1:m; %end % %x = x(:).'; % Row-vector. %y = y(:); % Column-vector. % %[m, n] = size(z); % %for i = 1:m % z(i, :) = z(i, :) + y(i); %end % %result = plot(x, z, varargin{:}); % %if nargout > 0, theResult = result; end fclose(fout); disp(' ## Installing: "xabx.m" (text)') fout = fopen('xabx.m', 'w'); %function [x, err_norm] = xabx(a, b, c, TRANSPOSE_FLAG) % %% xabx -- Solve x*a + b*x = c for x. %% xabx(a, b, c, 'TRANSPOSE_FLAG') solves the linear %% system x*a + b*x = c for x. If the TRANSPOSE_FLAG %% is any string, then the system to be solved is %% x'*a + b*x = c for x. %% xabx(a, c, 'TRANSPOSE_FLAG') solves the linear %% system x*a + a*x = c or x'*a + a*x = c for x. %% [x, err_norm] = ... returns x and the error-norm. % %% Copyright (C) 1997 Dr. Charles R. Denham, ZYDECO. %% All Rights Reserved. %% Disclosure without explicit written consent from the %% copyright owner does not constitute publication. % %if nargin < 1, help xabx, a = 2; end % %if nargin < 2 % n = a; % if isstr(n), n = eval(n); end % a = fix(rand(n, n) .* 10); % b = fix(rand(n, n) .* 10); % c = fix(rand(n, n) .* 10); % if n < 4, a, b, c, end % if nargout > 0 % [x, err_norm] = xabx(a, b, c); % else % xabx(a, b, c) % end % return %end % %flag = 0; % %if nargin == 4 % if isstr(TRANSPOSE_FLAG) % flag = 1; % end % elseif nargin == 3 % if isstr(c) % flag = 1; % c = b; % b = a; % end % elseif nargin == 2 % c = b; % b = a; %end % %[ma, na] = size(a); %[mb, nb] = size(b); %[mc, nc] = size(c); % %if na ~= nc | mb ~= mc % error(' ## Incompatible data sizes.') % return %end % %% Construct u and v as index-arrays for x. % %mv = nb; nv = nc; %v = zeros(mv, nv); v(:) = 1:prod(size(v)); %u = v; if flag, u = u.'; end %[mu, nu] = size(u); % %% Construct d to solve d * x(:) = c(:). % %d = zeros(prod(size(v)), prod(size(c))); % %% Assemble the x*a portion first. % %k = 0; %for j = 1:na % for i = 1:mu % indices = u(i, :); % k = k + 1; % d(k, indices) = d(k, indices) + a(:, j).'; % end %end % %% Assemble the b*x portion next. % %k = 0; %for j = 1:nv % for i = 1:mb % indices = v(:, j); % k = k + 1; % d(k, indices) = d(k, indices) + b(i, :); % end %end % %% Solve the system. % %v(:) = d \ c(:); % v is already the right size. % %% Error-norm. % %if nargout ~= 1 % u = v; if flag, u = u'; end % err_norm = norm(u*a + b*v - c); %end % %% Output. % %if nargout > 0 % x = v; % else % disp(' '), disp(['ans =']), disp(' '), disp(v), err_norm %end fclose(fout); disp(' ## Installing: "xy_simplify.m" (text)') fout = fopen('xy_simplify.m', 'w'); %function [xout, yout] = xy_simplify(x, y, nmax, tolerance) % %% xy_simplify -- Simplify an (x, y) contour. %% [xout, yout] = xy_simplify(x, y, nmax, tolerance) simplifies the (x, y) %% contour, returning nmax points if (nmax > 0) or those %% points that are more significant than the given tolerance. %% The ls_sort() routine is used, in which deviation, not %% curvature, is the key principle. NaNs are ignored. %% Nmax may be specified as a decimal fraction (0...1), %% or as an integer > 1. %% [out] = xy_simplify(...) returns [xout yout] in a single array. %% xy_simplify(nPoints) demonstrates itself with nPoints %% (random); default = 24. % %% Copyright (C) 1997 Dr. Charles R. Denham, ZYDECO. %% All Rights Reserved. %% Disclosure without explicit written consent from the %% copyright owner does not constitute publication. % %% Version of 06-Jul-1998 06:40:26. %% Updated 21-Sep-1998 17:13:27. % %% Reference: Douglas, D.H. and T.K. Peucker, Algorithms for %% the reduction of the number of points required to represent %% a digitized line of (sic?) its caricature, Can. Cartogr., %% 10, 112-122, 1973. We have adopted a similar scheme for %% selecting "significant" points. Unlike the D-P algorithm, %% we sort all the points first, then isolate those that satisfy %% our criteria for tolerance or total number of points retained. % %if nargin < 1, help(mfilename), x = 'demo'; end % %if isequal(x, 'demo'), x = 24; end % %if ischar(x), x = eval(x); end % %if length(x) == 1 % n = x; % x = 1:n; % y = cumsum(rand(size(x))-0.5); % y(ceil(n/2)) = NaN; % if (1), x(n) = x(1); y(n) = y(1); end % nmax = fix((n+2) ./ 3); % tolerance = 0; % tic % [xx, yy] = xy_simplify(x, y, nmax, tolerance); % toc % plot(xx, yy, '-*', x, y, 'o') % xlabel('x'), ylabel('y') % title('xy\_simplify') % set(gcf, 'Name', 'xy_simplify') % figure(gcf) % return %end % %if nargin < 3, nmax = 0; end %if nargin < 4 % if nmax == 0, nmax = length(lon); end % tolerance = 0; %end % %if nmax == 0, nmax = length(x); end % %if nmax > 0 & nmax <= 1 % nmax = round(nmax*length(x)); %end % %% Save NaNs. % %xx = x(:); %yy = y(:); % %i = find(isfinite(xx) & isfinite(yy)); %j = find(~isfinite(xx) | ~isfinite(yy)); %if any(i), xx = xx(i); yy = yy(i); end % %% Sort. % %[ind, dev] = ls_sort(xx, yy); % %% Restore NaNs: We need to decide how important %% the NaNs are -- most or least? If least, %% then we do not need to include them. % %ind = i(ind); %ind = [ind; j(:)]; %dev = [dev; NaN*j]; % %if nmax > 0 % nmax = max(3, min(nmax, length(x))); % ind = ind(1:nmax); % dev = dev(1:nmax); %else % f = find(dev >= tolerance); % if any(f) % ind = ind(f); % dev = dev(f); % end %end % %[ind, s] = sort(ind); %dev = dev(s); % %xx = x(ind); %yy = y(ind); % %if nargout == 1 % xout = [xx yy]; %elseif nargout > 1 % xout = xx; % yout = yy; %end % %function [theIndices, theDeviations] = ls_sort(x, y) % %% ls_sort -- Sort (x, y) data for line-simplification. %% [theIndices, theDeviations] = ls_sort(x, y) returns %% indices and deviations of the given (x, y) data, %% in order of decreasing importance for %% line-simplification. % %% Copyright (C) 1997 Dr. Charles R. Denham, ZYDECO. %% All Rights Reserved. %% Disclosure without explicit written consent from the %% copyright owner does not constitute publication. % %% Version of 02-Jul-1998 09:36:15. % %if nargin < 1, help(mfilename), x = 'demo'; end % %if isequal(x, 'demo'), x = 24; end % %if ischar(x), x = eval(x); end % %if length(x) == 1 % n = x; % x = 1:n; % y = cumsum(rand(size(x))-0.5); % tic % [i, d] = ls_sort(x, y); % toc % reduce = 3; % Reduction-factor. % k = fix((n+reduce-1)./reduce); % ii = i(1:k); % dd = d(1:k); % xx = x(ii); % yy = y(ii); % [ii, s] = sort(ii); % dd = dd(s); % xx = xx(s); % yy = yy(s); % subplot(2, 1, 1) % plot(x, y, 'bo', xx, yy, 'g-') % title('Data and Subset') % xlabel('x'), ylabel('y') % subplot(2, 1, 2) % plot(i, d, '.', xx, dd, 'o') % title('Deviation') % xlabel('x'), ylabel('y') % set(gcf, 'name', 'ls_sort demo') % figure(gcf) % return %end % %ind = zeros(size(x)); %dev = zeros(size(x)); % %nstack = ceil(1 + 2*log(length(x))/log(2)); %stack = zeros(nstack, 2); %nstack = 1; %stack(nstack, :) = [1 length(x)]; % %ind(1) = 1; %ind(2) = length(x); %k = 2; % %% Call ls_pivot() repeatedly and stack the %% longer interval before the shorter. % %while nstack > 0 % a = stack(nstack, 1); % b = stack(nstack, 2); % nstack = nstack - 1; % if b-a > 1 % [p, d] = ls_pivot(x([a:b]), y([a:b])); % if any(p) % p = a+p-1; % k = k+1; % ind(k) = p; % dev(k) = d; % if b-p >= p-a % if b-p > 1 % nstack = nstack + 1; % stack(nstack, :) = [p b]; % end % end % if p-a > 1 % nstack = nstack + 1; % stack(nstack, :) = [a p]; % end % if b-p < p-a % if b-p > 1 % nstack = nstack + 1; % stack(nstack, :) = [p b]; % end % end % end % end %end % %% Sort in descending order of importance. % %dev(1:2) = max(dev); %[ignore, s] = sort(-dev); %ind = ind(s); %dev = dev(s); % %% Output. % %if nargout > 0 % theIndices = ind; % theDeviations = dev; %else % ind, dev %end % %function [thePivot, theDeviation] = ls_pivot(x, y) % %% ls_pivot -- Line-simplification pivot. %% ls_pivot(x, y) returns the index of the (x, y) %% point that deviates most from the straight-line %% connection between the first and last of the %% given points. % %% Copyright (C) 1997 Dr. Charles R. Denham, ZYDECO. %% All Rights Reserved. %% Disclosure without explicit written consent from the %% copyright owner does not constitute publication. % %% Version of 02-Jul-1998 08:32:40. % %if nargin < 1, help(mfilename), x = 'demo'; end % %if isequal(x, 'demo'), x = 10; end % %if ischar(x), x = eval(x); end % %if length(x) == 1 % n = x; % x = 1:n; % y = cumsum(rand(size(x))-0.5); % tic % [piv, dev] = ls_pivot(x, y); % toc % plot(x, y, 'b-', x([1 n]), y([1 n]), 'g-', x(piv), y(piv), '*') % title(['ls\_pivot(' int2str(n) ')']) % xlabel('x'), ylabel('y') % figure(gcf) % return %end % %if nargin < 2, y = x; x = 1:length(y); end % %thePivot = 0; %theDeviation = -inf; % %n = length(x); %if n < 3, return, end % %% Translate to origin. % %x = x(:) - x(1); %y = y(:) - y(1); % %% Rotate onto x-axis about origin, then %% select the furthest point in y. %% If end-points are the same, we instead pick %% the point most distant from point #1. % %if any([x(1) y(1)] ~= [x(n) y(n)]) % r = norm([x(n) y(n)]); % c = x(n) ./ r; % s = y(n) ./ r; % z = [x y] * [c -s; s c]; %else % z = x + sqrt(-1)*y; % z = [z z]; %end % %% Find the pivot. % %temp = abs(z(2:n-1, 2)); %f = find(temp == max(temp)); %piv = f(1) + 1; %dev = abs(z(piv)); % %% Output. % %if nargout > 0 % thePivot = piv; % theDeviation = dev; %else % piv, dev %end fclose(fout); disp(' ## Installing: "ydrag.m" (text)') fout = fopen('ydrag.m', 'w'); %function [xout, yout] = ydrag(varargin) % %% ydrag -- Drag points in y-direction only. %% ydrag('demo') demonstrates itself. %% ydrag(N) demonstrates itself with N points. %% [xout, yout] = ydrag(x, y, ...) enables y-dragging %% of (x, y) points. Additional arguments are sent intact %% to the embedded "PLOT" command. To terminate and return %% the data, press any active key, or delete the window by %% clicking on its "goaway" box. If no output arguments %% are given, "xout" and "yout" are assigned to the caller's %% workspace. Note: this routine invokes "zoomsafe" for %% systems that have it. %% [xout, yout] = ydrag(y, ...) uses a default value of x, %% as in the Matlab "PLOT" command. %% ... = ydrag(aHandle) enables the line with the given %% handle, such as the "gco". %% ... = ydrag (no argument) enables an existing line, with %% priority given to one that was previously targetted %% by this routine. %% xyout = ... returns a two-column array of the (x, y) data. % %% Copyright (C) 2001 Dr. Charles R. Denham, ZYDECO. %% All Rights Reserved. %% Disclosure without explicit written consent from the %% copyright owner does not constitute publication. % %% Version of 03-Dec-2001 11:35:44. %% Updated 04-Dec-2001 11:12:35. % %persistent theLine %persistent thePointIndex %persistent oldFigureName %persistent oldNumberTitle %persistent oldPointer %persistent oldCloseRequestFcn %persistent deleteFlag % %CURSOR = 'circle'; % %if nargout > 0 % xout = []; % yout = []; %end % %% Demonstration. % %if nargin == 1 & isequal(varargin{1}, 'demo') % help(mfilename) % varargin{1} = 10; %end % %if nargin == 1 & ischar(varargin{1}) & any(varargin{1}(1) == '0123456789') % varargin{1} = eval(varargin{1}); %end % %if nargin == 1 & length(varargin{1}) == 1 & ~ischar(varargin{1}) % xmax = varargin{1}; % set(gcf, 'Name', [mfilename ' ' int2str(xmax)]) % xdemo = 0:xmax; % ydemo = rand(size(xdemo)); % xo = []; % yo = []; % [xo, yo] = feval(mfilename, xdemo, ydemo); % if nargout == 1 % xout = [xo(:) yo(:)]; % elseif nargout == 2 % xout = xo; % yout = yo; % else % assignin('caller', 'xout', xo) % assignin('caller', 'yout', yo) % disp(' ## See results in "xout" and "yout".') % end % return %end % %% New or existing line. % %doInitialize = ~~0; %if nargin >= 1 & ~ischar(varargin{1}) & length(varargin{1}) > 1 % theShadow = plot(varargin{:}); % set(theShadow, 'LineStyle', ':') % hold on % theLine = plot(varargin{:}); % if isequal(get(theLine, 'Marker'), 'none') % set(theLine, 'Marker', '*', 'MarkerEdgeColor', 'r') % end % hold off % doInitialize = ~~1; %elseif nargin == 1 & ~ischar(varargin{1}) & ishandle(varargin{1}) % theLine = varargin{1}; % doInitialize = ~~1; %elseif nargin < 1 % h = findobj(gca, 'Type', 'line', 'Tag', mfilename); % if ~any(h) % h = findobj(gca, 'Type', 'line'); % end % if ~any(h), return, end % theLine = h(1); % doInitialize = ~~1; %end % %% Initialize, then wait for keypress. %% We need to figure out how to handle %% a premature "CloseRequestFcn" callback. % %if doInitialize & ishandle(theLine) % theFigure = gcf; % set(theLine, ... % 'ButtonDownFcn', [mfilename ' down'], ... % 'Tag', mfilename) % try % zoomsafe on % catch % end % set(theFigure, 'UserData', []) % set(theFigure, 'KeyPressFcn', [mfilename ' keypress']) % oldCloseRequestFcn = get(theFigure, 'CloseRequestFcn'); % set(theFigure, 'CloseRequestFcn', [mfilename ' closereq']) % figure(theFigure) % % try % waitfor(theFigure, 'UserData', 'done') % Suspend. % catch % Catch any manual interrupt. % set(theFigure, 'CloseRequestFcn', oldCloseRequestFcn) % feval(mfilename, 'keypress') % end % % if ishandle(theFigure) % set(theFigure, 'UserData', []) % set(theFigure, 'KeyPressFcn', '') % set(theLine, 'ButtonDownFcn', '') % if ishandle(theLine) % xo = get(theLine, 'XData'); % yo = get(theLine, 'YData'); % set(theLine, 'ButtonDownFcn', '') % if nargout == 1 % xout = [x(:) y(:)]; % elseif nargout == 2 % xout = xo; % yout = yo; % else % assignin('caller', 'xout', xo) % assignin('caller', 'yout', yo) % disp(' ## See results in "xout" and "yout".') % end % end % if any(deleteFlag) % delete(theFigure) % end % end %end % %if nargin == 1 & ischar(varargin{1}) % theCommand = varargin{1}; % switch theCommand % case 'closereq' % deleteFlag = ~~1; % set(gcbf, 'UserData', 'done') % set(gcbf, 'CloseRequestFcn', oldCloseRequestFcn) % case 'keypress' % deleteFlag = ~~0; % set(gcbf, 'UserData', 'done') % set(gcbf, 'CloseRequestFcn', oldCloseRequestFcn) % case 'down' % xy = get(gca, 'CurrentPoint'); % oldFigureName = get(gcbf, 'Name'); % oldNumberTitle = get(gcbf, 'NumberTitle'); % oldPointer = get(gcbf, 'Pointer'); % set(gcbf, 'Name', num2str(xy(1, 2))) % set(gcbf, 'NumberTitle', 'off') % set(gcbf, 'Pointer', CURSOR) % xdown = xy(1, 1); % ydown = xy(1, 2); % xlim = get(gca, 'XLim'); % ylim = get(gca, 'YLim'); % xdata = get(theLine, 'XData'); % ydata = get(theLine, 'YData'); % oldUnits = get(gca, 'Units'); % set(gca, 'Units', 'pixels') % pos = get(gca, 'Position'); % set(gca, 'Units', oldUnits) % width = pos(3); % height = pos(4); % xdist = width * (xdata - xdown) / diff(xlim); % ydist = height * (ydata - ydown) / diff(ylim); % dist = abs(xdist + sqrt(-1) * ydist); % f = find(dist == min(dist)); % thePointIndex = f(1); % set(gcbf, 'WindowButtonMotionFcn', [mfilename ' motion']) % set(gcbf, 'WindowButtonUpFcn', [mfilename ' up']) % case 'motion' % xy = get(gca, 'CurrentPoint'); % set(gcbf, 'Name', num2str(xy(1, 2))) % case 'up' % xy = get(gca, 'CurrentPoint'); % set(gcbf, 'Name', num2str(xy(1, 2))) % xup = xy(1, 1); % yup = xy(1, 2); % ydata = get(theLine, 'YData'); % ydata(thePointIndex) = yup; % set(theLine, 'YData', ydata); % set(gcbf, 'Name', oldFigureName) % set(gcbf, 'NumberTitle', oldNumberTitle) % set(gcbf, 'Pointer', oldPointer) % set(gcbf, 'WindowButtonMotionFcn', '') % set(gcbf, 'WindowButtonUpFcn', '') % otherwise % end %end fclose(fout); disp(' ## Installing: "yearday.m" (text)') fout = fopen('yearday.m', 'w'); %function theResult = yearday(theYear, theDay) % %% yearday -- Convert date to year and day-of-year. %% yearday(theDate) returns [year day], where the day %% is a decimal date-number. The given date can be %% a Matlab datenum, datestr, or datevec. %% yearday([theYear theDay]) returns the Matlab datenum %% corresponding to theYear and theDay. %% yearday(theYear, theDay) same as above. %% yearday (no arguments) demonstrates itself by showing %% a round-trip, using "now". % %% Copyright (C) 1998 Dr. Charles R. Denham, ZYDECO. %% All Rights Reserved. %% Disclosure without explicit written consent from the %% copyright owner does not constitute publication. % %% Version of 09-Nov-1998 08:17:43. % %if nargin < 1, theYear = 'demo'; end % %if isequal(theYear, 'demo') % help(mfilename) % a = now; % disp(datestr(a)) % b = yearday(yearday(a)); % disp(datestr(b)) % year_day_round_trip_error = b-a % return %end % %% Two arguments: year and day ==> datenum. % %if nargin == 2, theYear = [theYear theDay]; end % %if length(theYear) == 2 % theDay = theYear(2); % theYear = theYear(1); % d = [theYear 1 1 0 0 0]; % January 1, midnight. % for i = 1:6 % v{i} = d(i); % end % result = datenum(v{:}) + theDay - 1; % if nargout > 0 % theResult = result; % else % disp(result) % end % return %end % %% One argument: date ==> year and day. % %theDate = theYear; % %if ischar(theDate) % theDate = datenum(theDate); %elseif length(theDate) > 1 % for i = 1:length(theDate) % v{i} = theDate(i); % end % theDate = datenum(v{:}); %end % %d = datevec(theDate); %d(2:6) = [1 1 0 0 0]; % January 1, midnight. %for i = 1:length(d) % v{i} = d(i); %end %newYearsDay = datenum(v{:}); % %delta = (theDate-newYearsDay); % %result = [d(1) (1+delta)]; % %if nargout > 0 % theResult = result; %else % disp(result) %end fclose(fout); disp(' ## Installing: "zoomsafe.m" (text)') fout = fopen('zoomsafe.m', 'w'); %function theResult = zoomsafe(varargin) % %% zoomsafe -- Safe zooming with the mouse. %% zoomsafe('demo') demonstrates itself with an interactive %% line. Zooming occurs with clicks that are NOT on the line. %% zoomsafe('on') initiates safe-zooming in the current window. %% Zooming occurs with each click in the current-figure, except %% on a graphical object whose "ButtonDownFcn" is active. %% zoomsafe('on', 'all') applies any new axis limits to all the %% axes in the figure. For companion axes having exactly the %% same 'XLim' range as the one that was clicked, the 'YLim' %% range remains intact. The same synchronization is invoked %% for corresponding 'YLim' situations as well. %% zoomsafe('all') same as zoomsafe('on', 'all'). %% zoomsafe (no argument) same as zoomsafe('on'). %% zoomsafe('off') turns it off. %% zoomsafe('out') zooms fully out. %% zoomsafe(theAmount, theDirection) applies theAmount of zooming %% to theDirection: 'x', 'y', or 'xy' (default). %% Note: when zooming actually occurs, this routine returns %% logical(1); otherwise, logical(0). %% %% "Click-Mode" (Macintosh Action) Result %% "normal" (click) Zoom out x2, centered on click. %% "extend" (shift-click) Zoom in x2, centered on click. %% "alt" (option-click) Center on click without zooming. %% "open" (double-click) Revert to unzoomed state. %% (Use click-down-and-drag to invoke a rubber-rectangle.) %% %% Use click-drag to map the zooming to a rubber-rectangle. % %% Copyright (C) 1997 Dr. Charles R. Denham, ZYDECO. %% All Rights Reserved. %% Disclosure without explicit written consent from the %% copyright owner does not constitute publication. % %% Version of 19-Jun-1997 08:42:57. %% Updated 02-Aug-1999 14:40:31. % %result = logical(0); % %if nargin < 1, varargin = {'on'}; end % %if isstr(varargin{1}) & ~isempty(varargin{1}) & ... % any(varargin{1}(1) == '0123456789.') % varargin{1} = eval(varargin{1}); %end % %if ~isstr(varargin{1}) % theAmount = varargin{1}; % varargin{1} = 'manual'; %end % %theFlag = logical(0); %isAll = logical(0); % %theOldXLim = get(gca, 'XLim'); %theOldYLim = get(gca, 'YLim'); % %switch varargin{1} %case 'manual' % isAll = (nargin > 2); % theDirection = 'xy'; % if nargin > 1, theDirection = varargin{2}; end % theXLim = get(gca, 'XLim'); % theYLim = get(gca, 'YLim'); % if theAmount == 0 % axis tight % switch theDirection % case 'x' % set(gca, 'YLim', theYLim) % case 'y' % set(gca, 'XLim', theXLim) % case 'xy' % otherwise % end % theAmount = 1; % theXLim = get(gca, 'XLim'); % theYLim = get(gca, 'YLim'); % end % cx = mean(theXLim); % cy = mean(theYLim); % dx = diff(theXLim) ./ 2; % dy = diff(theYLim) ./ 2; % switch theDirection % case 'x' % theXLim = cx + [-dx dx] ./ theAmount; % case 'y' % theYLim = cy + [-dy dy] ./ theAmount; % case 'xy' % theXLim = cx + [-dx dx] ./ theAmount; % theYLim = cy + [-dy dy] ./ theAmount; % otherwise % end % set(gca, 'XLim', theXLim, 'YLim', theYLim); % theFlag = 1; %case 'demo' % x = (0:30) ./ 30; % y = rand(size(x)) - 0.5; % for i = 2:-1:1 % subplot(1, 2, i) % theLine = plot(x, y, '-o'); % set(theLine, 'ButtonDownFcn', 'disp(''## hello'')') % set(gcf, 'Name', 'zoomsafe Demo') % end % result = zoomsafe('on', 'all'); %case 'all' % result = zoomsafe('on', 'all'); %case 'on' % isAll = (nargin > 1); % if ~isAll % set(gcf, 'WindowButtonDownFcn', 'if zoomsafe(''down''), end') % else % set(gcf, 'WindowButtonDownFcn', 'if zoomsafe(''down'', ''all''), end') % end %case 'down' % isAll = (nargin > 1); % dozoom = 0; % switch get(gcbo, 'Type') % case {'figure'} % "axes" not needed. % switch switchsafe(get(gco, 'Type')) % case {'figure'} % dozoom = 1; % otherwise % if isempty(get(gco, 'ButtonDownFcn')) % dozoom = 1; % end % end % otherwise % end % switch dozoom % case 1 % thePointer = get(gcf, 'Pointer'); % set(gcf, 'Pointer', 'watch') % theRBRect = rbrect; % x = sort(theRBRect([1 3])); % y = sort(theRBRect([2 4])); % theXLim = get(gca, 'XLim'); % theYLim = get(gca, 'YLim'); % theLimRect = [theXLim(1) theYLim(1) theXLim(2) theYLim(2)]; % d = doubleclick; % Trap any double-click. % if any(d) % Valid double-click. % if ~isAll % result = zoomsafe('out'); % else % result = zoomsafe('out', 'all'); % end % set(gcf, 'Pointer', 'arrow') % if nargout > 0, theResult = result; end % return % elseif isempty(d) % Ignore initial-click of double. % if nargout > 0, theResult = result; end % return % else % Not a double-click. % end % switch get(gcf, 'SelectionType') % case 'normal' % theFlag = 1; % theAmount = [2 2]; % Zoom-in by factor of 2. % case 'extend' % theFlag = 1; % theAmount = [0.5 0.5]; % case 'open' % Pre-empted by "doubleclick" above. % if ~isAll % result = zoomsafe('out'); % else % result = zoomsafe('out', 'all'); % end % set(gcf, 'Pointer', 'arrow') % if nargout > 0, theResult = result; end % return % otherwise % theAmount = [1 1]; % x = [mean(x) mean(x)]; % y = [mean(y) mean(y)]; % end % if diff(x) == 0 | diff(y) == 0 % cx = mean(x); % cy = mean(y); % dx = diff(theXLim) ./ 2; % dy = diff(theYLim) ./ 2; % x = cx + [-dx dx] ./ theAmount(1); % y = cy + [-dy dy] ./ theAmount(2); % else % r1 = theLimRect; % r2 = theRBRect; % switch get(gcf, 'SelectionType') % case 'normal' % r4 = maprect(r1, r2, r1); % case 'extend' % r4 = maprect(r2, r1, r1); % otherwise % r4 = r1; % end % x = r4([1 3]); % y = r4([2 4]); % end % set(gca, 'XLim', sort(x), 'YLim', sort(y)) % theFlag = 1; % result = logical(1); % switch thePointer % case {'watch', 'circle'} % thePointer = 'arrow'; % otherwise % end % set(gcf, 'Pointer', thePointer) % set(gcf, 'Pointer', 'arrow') % otherwise % end %case 'motion' %case 'up' %case 'off' % set(gcf, 'WindowButtonDownFcn', ''); %case 'out' % isAll = (nargin > 1); % theFlag = 1; % axis tight % result = logical(1); %otherwise % temp = eval(varargin{1}); % switch class(temp) % case 'double' % if ~isAll % result = zoomsafe(temp); % else % result = zoomsafe(temp, 'all'); % end % otherwise % warning('## Unknown option') % end %end % %% Synchronize the other axes. % %if isAll & theFlag & 1 % theGCA = gca; % theXLim = get(theGCA, 'XLim'); % theYLim = get(theGCA, 'YLim'); % theAxes = findobj(gcf, 'Type', 'axes'); % for i = 1:length(theAxes) % if theAxes(i) ~= theGCA % axes(theAxes(i)) % x = get(gca, 'XLim'); % y = get(gca, 'YLim'); % if all(x == theOldXLim) % set(theAxes(i), 'XLim', theXLim) % end % if all(y == theOldYLim) % set(theAxes(i), 'YLim', theYLim) % end % end % end % axes(theGCA) %end % %if nargout > 0, theResult = result; end % %% legend % Causes excessive flashing. % %function theResult = rbrect(onMouseUp, onMouseMove, onMouseDown) % %% rbrect -- Rubber rectangle tracking (Matlab-4 and Matlab-5). %% rbrect('demo') demonstrates itself. %% rbrect('onMouseUp', 'onMouseMove', 'onMouseDown') conducts interactive %% rubber-rectangle tracking, presumably because of a mouse button press %% on the current-callback-object (gcbo). The 'on...' callbacks are %% automatically invoked with: "feval(theCallback, theInitiator, theRect)" %% after each window-button event, using the object that started this %% process, plus theRect as [xStart yStart xEnd yEnd] for the current %% rubber-rect. The callbacks default to ''. The coordinates of the %% rectangle are returned as [xStart yStart xEnd yEnd]. % %% Private interface: %% rbrect(1) is automatically called on window-button-motions. %% rbrect(2) is automatically called on window-button-up. % %% Copyright (C) 1997 Dr. Charles R. Denham, ZYDECO. %% All Rights Reserved. %% Disclosure without explicit written consent from the %% copyright owner does not constitute publication. % %% Version of 03-Jun-1997 15:54:39. %% Version of 11-Jun-1997 15:17:22. %% Version of 17-Jun-1997 16:52:46. % %global RBRECT_HANDLE %global RBRECT_INITIATOR %global RBRECT_ON_MOUSE_MOVE % %if nargin < 1, onMouseUp = 0; end % %if strcmp(onMouseUp, 'demo') % help rbrect % x = cumsum(rand(200, 1) - 0.45); % y = cumsum(rand(200, 1) - 0.25); % h = plot(x, y, '-r'); % set(h, 'ButtonDownFcn', 'disp(rbrect)') % figure(gcf), set(gcf, 'Name', 'RBRECT Demo') % return % elseif isstr(onMouseUp) % theMode = 0; % else % theMode = onMouseUp; % onMouseUp = ''; %end % % %if theMode == 0 % Mouse down. % if nargin < 3, onMouseDown = ''; end % if nargin < 2, onMouseMove = ''; end % if nargin < 1, onMouseUp = ''; end % theVersion = version; % isVersion5 = (theVersion(1) == '5'); % if isVersion5 % theCurrentObject = 'gcbo'; % else % theCurrentObject = 'gco'; % end % RBRECT_INITIATOR = eval(theCurrentObject); % switch get(RBRECT_INITIATOR, 'Type') % case 'line' % theColor = get(RBRECT_INITIATOR, 'Color'); % otherwise % theColor = 'black'; % end % RBRECT_ON_MOUSE_MOVE = onMouseMove; % pt = mean(get(gca, 'CurrentPoint')); % x = [pt(1) pt(1)]; y = [pt(2) pt(2)]; % RBRECT_HANDLE = line(x, y, ... % 'EraseMode', 'xor', ... % 'LineStyle', '--', ... % 'LineWidth', 2.5, ... % 'Color', theColor, ... % 'Marker', '+', 'MarkerSize', 13, ... % 'UserData', 1); % set(gcf, 'WindowButtonMotionFcn', 'rbrect(1);') % set(gcf, 'WindowButtonUpFcn', 'rbrect(2);') % theRBRect = [x(1) y(1) x(2) y(2)]; % if ~isempty(onMouseDown) % feval(onMouseDown, RBRECT_INITIATOR, theRBRect) % end % thePointer = get(gcf, 'Pointer'); % set(gcf, 'Pointer', 'circle'); % if isVersion5 & 0 % Disable for rbrect().. % eval('waitfor(RBRECT_HANDLE, ''UserData'', [])') % else % set(RBRECT_HANDLE, 'Visible', 'off') % Invisible. % eval('rbbox') % No "waitfor" in Matlab-4. % end % set(gcf, 'Pointer', thePointer); % set(gcf, 'WindowButtonMotionFcn', '') % set(gcf, 'WindowButtonUpFcn', '') % x = get(RBRECT_HANDLE, 'XData'); % y = get(RBRECT_HANDLE, 'YData'); % delete(RBRECT_HANDLE) % theRBRect = [x(1) y(1) x(2) y(2)]; % Scientific. % if ~isempty(onMouseUp) % feval(onMouseUp, RBRECT_INITIATOR, theRBRect) % end %elseif theMode == 1 % Mouse move. % pt2 = mean(get(gca, 'CurrentPoint')); % x = get(RBRECT_HANDLE, 'XData'); % y = get(RBRECT_HANDLE, 'YData'); % x(2) = pt2(1); y(2) = pt2(2); % set(RBRECT_HANDLE, 'XData', x, 'YData', y) % theRBRect = [x(1) y(1) x(2) y(2)]; % if ~isempty(RBRECT_ON_MOUSE_MOVE) % feval(RBRECT_ON_MOUSE_MOVE, RBRECT_INITIATOR, theRBRect) % end %elseif theMode == 2 % Mouse up. % pt2 = mean(get(gca, 'CurrentPoint')); % x = get(RBRECT_HANDLE, 'XData'); % y = get(RBRECT_HANDLE, 'YData'); % x(2) = pt2(1); y(2) = pt2(2); % set(RBRECT_HANDLE, 'XData', x, 'YData', y, 'UserData', []) %else %end % %if nargout > 0, theResult = theRBRect; end % %function rect4 = maprect(rect1, rect2, rect3) % %% maprect -- Map rectangles. %% maprect(rect1, rect2, rect3) returns the rectangle %% that is to rect3 what rect1 is to rect2. Each %% rectangle is given as [x1 y1 x2 y2]. %% maprect('demo') demonstrates itself by showing %% that maprect(r1, r2, r1) ==> r2. % %% Copyright (C) 1997 Dr. Charles R. Denham, ZYDECO. %% All Rights Reserved. %% Disclosure without explicit written consent from the %% copyright owner does not constitute publication. % %% Version of 19-Jun-1997 08:33:39. % %if nargin < 1, help(mfilename), rect1 = 'demo'; end % %if strcmp(rect1, 'demo') % rect1 = [0 0 3 3]; % rect2 = [1 1 2 2]; % rect3 = rect1; % r4 = maprect(rect1, rect2, rect3); % begets(mfilename, 3, rect1, rect2, rect3, r4) % return %end % %if nargin < 3, help(mfilename), return, end % %r4 = zeros(1, 4); %i = [1 3]; %for k = 1:2 % r4(i) = polyval(polyfit(rect1(i), rect2(i), 1), rect3(i)); % i = i + 1; %end % %if nargout > 0 % rect4 = r4; % else % disp(r4) %end % %function theResult = doubleclick % %% doubleclick -- Trap for double-clicks. %% doubleclick (no argument) returns TRUE if a click %% is detected during its execution; otherwise, FALSE. %% Call "doubleclick" during a "WindowButtonDown" or %% "ButtonDown" callback, preferably at the top of %% procedure. The 'Interruptible' property of the %% callback-object must be 'on'. The double-click %% time is 0.5 sec. A valid double-click causes %% two values to be returned: first, a logical(1), %% then an empty-matrix []. The latter signifies %% the single-click that initiated the process. %% For a valid single-click, only logical(0) is %% returned. % %% Copyright (C) 1997 Dr. Charles R. Denham, ZYDECO. %% All Rights Reserved. %% Disclosure without explicit written consent from the %% copyright owner does not constitute publication. % %% Version of 25-Jul-1998 09:47:16. % %global CLICK_COUNT % %DOUBLE_CLICK_TIME = 1/2; % Seconds. % %if isempty(CLICK_COUNT), CLICK_COUNT = 0; end % %CLICK_COUNT = CLICK_COUNT + 1; % %if CLICK_COUNT == 1 % tic % while isequal(CLICK_COUNT, 1) & toc < DOUBLE_CLICK_TIME, end %end % %drawnow % Process the event-cue. % %% Note: %% Despite the "drawnow" seen above, Matlab does not %% update the "SelectionType" in timely fashion, so %% it cannot be used to trap a double-click properly. % %result = (CLICK_COUNT > 1); % %CLICK_COUNT = []; % %if nargout > 0 % theResult = result; %else % disp(result) %end fclose(fout); cd ('..') disp(' ') disp(' ## Add "snackbar" to your Matlab path.') disp(' ## Then restart Matlab.')