subsref.m
来自「matlab实用教程」· M 代码 · 共 28 行
M
28 行
function b = subsref(s,index)
% SUBSREF Define field name indexing for stock objects
fc = fieldcount(s.asset);
switch index.type
case '()'
if (index.subs{:} <= fc)
b = subsref(s.asset,index);
else
switch index.subs{:} - fc
case 1
b = s.numShares;
case 2
b = s.sharePrice;
otherwise
error(['Index must be in the range 1 to ', ...
num2str(fc + 2)])
end
end
case '.'
switch index.subs
case 'numShares'
b = s.numShares;
case 'sharePrice'
b = s.sharePrice;
otherwise
b = subsref(s.asset,index);
end
end
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?