subsasgn.m

来自「matlab实用教程」· M 代码 · 共 28 行

M
28
字号
function s = subsasgn(s,index,val)
% SUBSASGN Define index assignment for stock objects
fc = fieldcount(s.asset);
switch index.type
case '()'
   if (index.subs{:} <= fc)
      s.asset = subsasgn(s.asset,index,val);
   else
      switch index.subs{:}-fc
      case 1
         s.numShares = val;
      case 2
         s.sharePrice = val;
      otherwise
         error(['Index must be in the range 1 to ', ...
            num2str(fc + 2)])
      end
   end
case '.'
   switch index.subs
   case 'numShares'
      s.numShares = val;
   case 'sharePrice'
      s.sharePrice = val;
   otherwise
      s.asset = subsasgn(s.asset,index,val);
   end
end

⌨️ 快捷键说明

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