par2struct.m

来自「麻省理工学院的人工智能工具箱,很珍贵,希望对大家有用!」· M 代码 · 共 26 行

M
26
字号
function S=par2struct(S,lin,tok,num)
%Function to process a line to a struct, tokenized by tok
mas=1;
while(mas)
   [t, lin] = strtok(lin, ',');
   if(isempty(t))
      t=lin;
      mas=0;
   end
   [t2,r2] = strtok(t,'=');
   if(~isempty(t2))
      campo=deblank(fliplr(deblank(fliplr(t2))));
      valor=deblank(fliplr(deblank(fliplr(r2(2:end)))));
      if(~isfield(S,campo))
         error([campo ' is not field of struct']);
      end
      
      switch(campo)
         case num
            valor=str2num(valor);            
      end
      %sprintf(':%s:%s:',campo,valor)   
      S=setfield(S,campo,valor);
   end
end

⌨️ 快捷键说明

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