Home > FMAToolbox > Database > GetBatch.m

GetBatch

PURPOSE ^

GetBatch - Get batch job output.

SYNOPSIS ^

function varargout = GetBatch(batch)

DESCRIPTION ^

GetBatch - Get batch job output.

  USAGE

    [output1,output2,...] = GetBatch(batch)

    batch          batch parameter returned by <a href="matlab:help StartBatch">StartBatch</a>

  OUTPUT

    output1...     one matrix or cell array for each output parameter of the
                   batch function, listing the result of each individual iteration
                   on a separate line

  EXAMPLE

    % Start a batch in 4 hours
    >> b = StartBatch(@SomeComputation,'batchfile.txt',4*60);

    % Come back in 3 hours and try getting the results
    >> output = GetBatch(b);
    Warning: Batch not finished...

    % Come back the following morning and get the results
    >> output = GetBatch(b);

  SEE

    See also StartBatch, BatchInfo, CancelBatch, CleanBatches, Store, Recall.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function varargout = GetBatch(batch)
0002 
0003 %GetBatch - Get batch job output.
0004 %
0005 %  USAGE
0006 %
0007 %    [output1,output2,...] = GetBatch(batch)
0008 %
0009 %    batch          batch parameter returned by <a href="matlab:help StartBatch">StartBatch</a>
0010 %
0011 %  OUTPUT
0012 %
0013 %    output1...     one matrix or cell array for each output parameter of the
0014 %                   batch function, listing the result of each individual iteration
0015 %                   on a separate line
0016 %
0017 %  EXAMPLE
0018 %
0019 %    % Start a batch in 4 hours
0020 %    >> b = StartBatch(@SomeComputation,'batchfile.txt',4*60);
0021 %
0022 %    % Come back in 3 hours and try getting the results
0023 %    >> output = GetBatch(b);
0024 %    Warning: Batch not finished...
0025 %
0026 %    % Come back the following morning and get the results
0027 %    >> output = GetBatch(b);
0028 %
0029 %  SEE
0030 %
0031 %    See also StartBatch, BatchInfo, CancelBatch, CleanBatches, Store, Recall.
0032 %
0033 
0034 % Copyright (C) 2010-2011 by Michaƫl Zugaro
0035 %
0036 % This program is free software; you can redistribute it and/or modify
0037 % it under the terms of the GNU General Public License as published by
0038 % the Free Software Foundation; either version 3 of the License, or
0039 % (at your option) any later version.
0040 
0041 % Check number of parameters
0042 if nargin < 1,
0043     error('Incorrect number of parameters (type ''help <a href="matlab:help GetBatch">GetBatch</a>'' for details).');
0044 end
0045 if prod(size(batch)) ~=1 || ~isa(batch,'timer') || ~isvalid(batch) || ~strcmp(get(batch,'Tag'),'BatchJob'),
0046     error('Invalid batch job (type ''help <a href="matlab:help GetBatch">GetBatch</a>'' for details).');
0047 end
0048 
0049 if strcmp(get(batch,'Running'),'on'),
0050     warning('Batch not finished...');
0051     output = [];
0052 else
0053     output = get(batch,'UserData');
0054 end
0055 
0056 if nargout > size(output,2),
0057     error('Too many output parameters (type ''help <a href="matlab:help GetBatch">GetBatch</a>'' for details).');
0058 end
0059 
0060 for i = 1:max([1 nargout]),
0061     if isnumeric(output{1,i}) || islogical(output{1,i}),
0062         % If this parameter is numeric or logical and all instances have the same size, concatenate,
0063         % otherwise return a cell array
0064         if any(diff(cellfun('size',output,2))),
0065             varargout{i} = {output{:,i}}';
0066         else
0067             varargout{i} = vertcat(output{:,i});
0068         end
0069     else
0070         varargout{i} = {output{:,i}}';
0071     end
0072 end
0073

Generated on Fri 16-Mar-2018 13:00:20 by m2html © 2005