www.gusucode.com > mbcdata 工具箱 matlab 源码程序 > mbcdata/@calibrationdata/@matinterface/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;
axisIdentifiers = calibration.getAxisIdentifiers;
curveIdentifiers = calibration.getCurveIdentifiers;
mapIdentifiers = calibration.getMapIdentifiers;

% Store lengths for convenience
nValues = numel(valueIdentifiers);
nAxes = numel(axisIdentifiers);
nCurves = numel(curveIdentifiers);
nMaps = numel(mapIdentifiers);

% Process values
values = []; % initialize
if nValues > 0
    pm.notify(sprintf('Processing %d values', nValues));
    for i = 1:nValues,
        thisO = calibration.getValue(valueIdentifiers{i});
        thisS = getMemento(thisO);
        values = [values thisS]; % safe but slow
        pm.update(i/(nValues+nAxes+nCurves+nMaps));
    end
end

% Process axes
axes = []; % initialize
if nAxes > 0
    pm.notify(sprintf('Processing %d axes', nAxes));
    for i = 1:nAxes,
        thisO = calibration.getAxis(axisIdentifiers{i});
        thisS = getMemento(thisO);
        axes = [axes thisS]; % safe but slow
        pm.update((i+nValues)/(nValues+nAxes+nCurves+nMaps));
    end
end

% Process curves
curves = []; % initialize
if nCurves > 0
    pm.notify(sprintf('Processing %d curves', nCurves));
    for i = 1:nCurves,
        thisO = calibration.getCurve(curveIdentifiers{i});
        thisS = getMemento(thisO);
        curves = [curves thisS]; % safe but slow
        pm.update((i+nValues+nAxes)/(nValues+nAxes+nCurves+nMaps));
    end
end

% Convert maps to structure
maps = []; % initialize
if nMaps > 0
    pm.notify(sprintf('Processing %d maps', nMaps));
    for i = 1:nMaps,
        thisO = calibration.getMap(mapIdentifiers{i});
        thisS = getMemento(thisO);
        maps = [maps thisS]; % safe but slow
        pm.update((i+nValues+nAxes+nCurves)/(nValues+nAxes+nCurves+nMaps));
    end
end

% Save structure
pm.notify('Writing file to disk');
dataStructure.Values = values;
dataStructure.Axes = axes;
dataStructure.Curves = curves;
dataStructure.Maps = maps;
calibration = dataStructure; % confused? variable name in MAT file is 'calibration'
matlabVersion = str2num(version('-release'));
if matlabVersion < 14
    save(filename, 'calibration', '-mat');
else
    save(filename, 'calibration', '-mat', '-v6');
end

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