⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 assign_input.m

📁 实现地震勘探中
💻 M
字号:
function param=assign_input(param,arguments,fcn)% Function matches keywords in cell array "arguments" to fields of "param", and % replaces them with new values. Used to assign input arguments in certain functions%% Written by: E. R.:% Last updated: March 31, 2008: replace "disp" by disps" where appropriate. %%          param=assign_input(param,arguments,fcn)% INPUT% param    structure% arguments cell array, each element of "arguments" is a 2-element cell array%          whose first element is a field name of "param"% fcn      string with the name of the function calling "assign_input";%          optional% OUTPUT% param    input structure updated with values in "arguments"%                     param=assign_input(param,arguments}% Input can also be provided via global variable "PARAMETERS4FUNCTION"% GLOBAL VARIABLE%          PARAMETERS4FUNCTION   structure with field "fcn" which, in turn, has fields%                   'default' and/or 'actual'%          Example: PARAMETERS4FUNCTION.s_iplot.default%                   PARAMETERS4FUNCTION.s_iplot.actual%          PARAMETERS4FUNCTION.s_iplot.actual is a structure with the actually used parameters%          i.e. it has has the same fields as "param" on output% UPDATE HISTORY%          September 17, 2006: always assign cell content if keyword %                                   has only one valueglobal PARAMETERS4FUNCTIONier=0;%	Check if arguments are supplied via global variable "PARAMETERS4FUNCTION.fcn.default"			if nargin > 2if isfield(PARAMETERS4FUNCTION,fcn)   temp=PARAMETERS4FUNCTION.(fcn);   if isfield(temp,'default')  &&  ~isempty(temp.default)      defaults=temp.default;      fields=fieldnames(defaults);      params=fieldnames(param);      bool=ismember(fields,params);      if ~all(bool)         disp(['Parameters specified via "PARAMETERS4FUNCTION.',fcn,'.default":'])         disps(cell2str(fields,', '))         fields=fields(~bool);         disp('Parameters that are not keywords of function:')         disps(cell2str(fields,', '))         disp('Possible keywords: ')         disps(cell2str(params,', '))	 temp.default=[];%	Set "PARAMETERS4FUNCTION.functionname.default" to the empty matrix to prevent                                % it from being used again in another function	 PARAMETERS4FUNCTION.(fcn)=temp; 	         error(['Not all fields of "PARAMETERS4FUNCTION.',fcn,'.default" are keywords'])      end        for ii=1:length(fields)         param.(fields{ii})=temp.default.(fields{ii});      end%     Set "PARAMETERS4FUNCTION.functionname.default" to the empty matrix to prevent                                % it from being used again in another function      temp.default=[];      PARAMETERS4FUNCTION.(fcn)=temp;    endend			end%	Use input arguments of the function calling "assign_input"for ii=1:length(arguments)   arg=arguments{ii};   field=lower(arg{1});   if ~isfield(param,field)      if ier == 0         temp=dbstack;         temp=temp(2).name;         idx1=findstr(temp,'\');         idx2=findstr(temp,'.');	 try            funct=upper(temp(idx1(end)+1:idx2(end)-1));	    disp([' "',field,'" is not a valid input argument keyword for ',funct])    catch  %#ok	    disp([' "',field,'" is not a valid input argument keyword.'])	    funct='an unidentified function';	 end      end           ier=1;      else%      if length(arg) == 2 && ~iscell(arg{2})      % Modification       if length(arg) == 2                % Modified 9/17/2006         param.(field)=arg{2};      else         param.(field)=arg(2:end);      end   endendif ier   disp('Recognized keywords are:')   disps(cell2str(fieldnames(param),', '))   error(['Input error in ',funct]) endif nargin > 2   temp.actual=param;   PARAMETERS4FUNCTION.(fcn)=temp; end

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -