www.gusucode.com > mbctools 工具箱 matlab 源码程序 > mbctools/@sweepset/append.m
function [out, OK, msg] = append(SS1, SS2,option) %APPEND Append one sweepset to another % % [SS, OK, MSG] = APPEND(SS1, SS2) appends SS2 to the end of SS1. % Copyright 2000-2015 The MathWorks, Inc. and Ford Global Technologies, Inc. msg = ''; if nargin>2 && strcmp(option,'strict') [SS1,msg] = strictIntersect(SS1,SS2); else % Find common names nameSS1 = get(SS1, 'Name'); SS2 = sort(SS2); nameSS2 = get(SS2, 'Name'); [common, com1, com2] = intersect(nameSS1, nameSS2); if ~isempty(common) % Create the append data matrix, full of NaN to account for missing data dataToAppend = NaN(numRecords(SS2), numDataVariables(SS1)); baddataToAppend = sparse(dataToAppend); % Now get the new data dataToAppend(:, com1) = SS2.data(:, com2); baddataToAppend(:, com1) = SS2.baddata(:, com2); SS1.data = [SS1.data; dataToAppend]; SS1.baddata = [SS1.baddata; baddataToAppend]; SS1.guid = [SS1.guid; SS2.guid]; SS1.xregdataset = [SS1.xregdataset; SS2.xregdataset]; else msg = 'No common variables found in appended data'; end end OK = isempty(msg); if OK out = SS1; else out = sweepset; end function [SS1,msg] = strictIntersect(SS1,SS2) % sort by names SS1 = sort(SS1); SS2 = sort(SS2); OK = isequal(get(SS1, 'Name'),get(SS2, 'Name')) && isequal(get(SS1, 'Units'),get(SS2, 'Units')); if OK % concatenate msg = ''; SS1.data = [SS1.data; SS2.data]; SS1.baddata = [SS1.baddata; SS2.baddata]; SS1.guid = [SS1.guid; SS2.guid]; SS1.xregdataset = [SS1.xregdataset; SS2.xregdataset]; else msg = 'Variables are missing from data set or units do not match.'; end