www.gusucode.com > mbctools 工具箱 matlab 源码程序 > mbctools/@sweepset/find.m
function [ind , allind] = find(S, var) %FIND Find variables in the sweepset % % IND = FIND(S, VAR) returns the index of the SWEEPSET database variable % matching VAR. VAR may be a single name or a cell array of names. An % empty matrix is returned if any one of VAR is not found. % % If any variables were not found, then the indices of those that were % are returned as a second argument. In this output the index for % variables that are not found is set to -1. % Copyright 2000-2015 The MathWorks, Inc. and Ford Global Technologies, Inc. var = xregdeblank(var); varlist = {S.var.name}; if ~iscell(var) var = {var}; end if isscalar(var) OK = strcmp(var,varlist); ind = find(OK); if nargout>1 allind = ind; if isempty(allind) allind = -1; end end else [OK,allind] = ismember(var,varlist); if all(OK) ind = allind; else % If any variables are not found, the first output is empty. The second % output always contains the full set of integers with -1 % indicating that a variable is not found. ind = []; allind(~OK) = -1; end end