Numerical Linear Algebra Project, Part Trois
In order to automate the saving of our matrices, we wrote our own program called generateMatrices.m
The code is as follows:
/* Authors: Hank Turowski     hturowsk@math.ucdenver.edu
*          Sarah Boerckel    sboercek@math.ucdenver.edu
*
* Note: Permission to use this code for academic purposes is granted
*        as long as credit is given to the orginal authors.
*/
			
img=im2double(imread('d:/MATLAB7/work/clouds.jpg'));
stopIso=1e-5;
stopNcuts=5e-2;
scaleIso=95;
scaleNcuts=35;
%Resize to make script run faster
[X Y Z]=size(img);
img=imresize(img,[floor(X/2),floor(Y/2)]);
[X Y Z]=size(img);
% 4-connected spectral
imgsegment(img,scaleIso,stopIso,1,1,0,0,0,'4spectral');
% 4-connected N-Cuts
imgsegment(img,scaleIso,stopIso,1,0,0,0,0,'4ncuts');
% 8-connected spectral
imgsegment(img,scaleIso,stopIso,1,1,1,0,0,'8spectral');
% 8-connected N-Cuts
imgsegment(img,scaleIso,stopIso,1,0,1,0,0,'8ncuts');

 
We located those files in the original code that created the matrices and modified them so that they accepted an optional file name argument and then pass the matrices to the dumpmatrix() along with the optional file name.
 
We also modified the following functions to take an additional argument: the 'fname' argument
1. imgsegment() now takes fname as its 9th argument
2. recursivepartition() now takes fname as its 6th argument
3. partitiongraph() now takes fname as its 7th argument
4. and in recursivepartition.m we modified performrecursion() to take fname as its 10th argument
In order to abort the recursive process, we checked to see if the fname variable had been passed to performrecursion(), and if so, we exited performrecursion() imediately after the call to eigs().
Lastly, we expanded our dumpmatrix(). The code is as follows:
/* Authors: Hank Turowski     hturowsk@math.ucdenver.edu
*          Sarah Boerckel    sboercek@math.ucdenver.edu
*
* Note: Permission to use this code for academic purposes is granted
*        as long as credit is given to the orginal authors.
*/
                        
function dumpmatrix(fname, varargin)
if isa(varargin{1},'double')
  filename = [fname, '.mat'];
  if ~exist(filename)
     A = varargin{1};
     save(fname, 'A');
     sprintf('Saved matrix to %s.mat', fname)
  end
end

In the code, we're now checking to see if the file exists before we create it. If the file already exists, we simply exit.

fin