www.gusucode.com > mbcdata 工具箱 matlab 源码程序 > mbcdata/@calibrationdata/@visionv2matinterface/pWrite.m

    function pWrite(obj, calibration, filename)
%PWRITE  Private static method.

%  PWRITE writes a calibration to a MAT file.
%
%  PWRITE(OBJ,CALIBRATION,FILENAME)
%
%  See also COMMIT, PREAD.

%  Copyright 2000-2011 The MathWorks, Inc.


narginchk(3,3);
nargoutchk(0,0);

% Do not write to empty
if isempty(filename)
    return
end

pm = obj.ProgressManager;
pm.reset;
pm.notify('Performing startup tasks');

% Get identifiers
valueIdentifiers = calibration.getValueIdentifiers;
curveIdentifiers = calibration.getCurveIdentifiers;
mapIdentifiers = calibration.getMapIdentifiers;

% Store lengths for convenience
nValues = numel(valueIdentifiers);
nAxes = 0; % axes are not treated separately
nCurves = numel(curveIdentifiers);
nMaps = numel(mapIdentifiers);

% Preallocate output
ATICALParameterList = struct('GroupData', 1, 'Scalar', [], ...
    'Table2D', [], 'Table3D', [], 'State', [], 'Array1D', [], ...
    'Array2D', [], 'Text', []);
emptyStruct = struct('Name',[],'XAxis',[],'YAxis',[],'ZAxis',[]);
scalar = repmat(emptyStruct, 1, nValues);
table2D = repmat(emptyStruct, 1, nCurves);
table3D = repmat(emptyStruct, 1, nMaps);

% Process values
if nValues > 0
    pm.notify(sprintf('Retrieving %d values', nValues));
    values = calibration.getValue(valueIdentifiers);
    valueValues = get(values, {'Value'});
    pm.notify(sprintf('Processing %d values', nValues));
    for i = 1:nValues,
        scalar(i).Name = valueIdentifiers{i};
        scalar(i).XAxis = valueValues{i};
        pm.update(i/(nValues+nAxes+nCurves+nMaps));
    end
end

% Process curves
if nCurves > 0
    pm.notify(sprintf('Retrieving %d curves', nCurves));
    curves = calibration.getCurve(curveIdentifiers);
    xAxes = calibration.getAxis(get(curves, {'XAxisIdentifier'}));
    curveValues = get(curves, {'Value'});
    xAxisValues = get(xAxes, {'Value'});
    pm.notify(sprintf('Processing %d curves', nCurves));
    for i = 1:nCurves,
        table2D(i).Name = curveIdentifiers{i};
        table2D(i).XAxis = transpose(xAxisValues{i});
        table2D(i).YAxis = transpose(curveValues{i});
        pm.update((i+nValues+nAxes)/(nValues+nAxes+nCurves+nMaps));
    end
end

% Process maps
if nMaps > 0
    pm.notify(sprintf('Retrieving %d maps', nMaps));
    maps = calibration.getMap(mapIdentifiers);
    xAxes = calibration.getAxis(get(maps, {'XAxisIdentifier'}));
    yAxes = calibration.getAxis(get(maps, {'YAxisIdentifier'}));
    mapValues = get(maps, {'Value'});
    xAxisValues = get(xAxes, {'Value'});
    yAxisValues = get(yAxes, {'Value'});
    pm.notify(sprintf('Processing %d maps', nMaps));
    for i = 1:nMaps,
        table3D(i).Name = mapIdentifiers{i};
        table3D(i).XAxis = transpose(xAxisValues{i});
        table3D(i).YAxis = transpose(yAxisValues{i});
        table3D(i).ZAxis = transpose(mapValues{i});
        pm.update((i+nValues+nAxes+nCurves)/(nValues+nAxes+nCurves+nMaps));
    end
end

% Save structure
pm.notify('Writing file to disk');
ATICALParameterList.Scalar = scalar;
ATICALParameterList.Table2D = table2D;
ATICALParameterList.Table3D = table3D;
matlabVersion = str2num(version('-release'));
if matlabVersion < 14
    save(filename, 'ATICALParameterList', '-mat');
else
    save(filename, 'ATICALParameterList', '-mat', '-v6');
end

pm.update(1);
pm.notify('Cleaning up');