在下面的示例中,如何将 Ann 的年龄设置为 40?
>> d(1,1).Name='John'; d(1,1).Age=30;
>> d(2,1).Name='Anne'; d(2,1).Age=31;
>> ds=struct2dataset(d,'ReadObsNames','Name');
>> ds
ds =
Age
John 30
Anne 31
>> ds(2,'Name')
Error using getvarindices (line 25)
Unrecognized variable name 'Name'.
Error in dataset/subsrefParens (line 19)
varIndices = getvarindices(a, s(1).subs{2});
Error in dataset/subsref (line 69)
[varargout{1:nargout}] = subsrefParens(a,s);
>> ds(2,'Age')
ans =
Age
Anne 31
>> ds(2,'Age')=40
Error using dataset/subsasgnParens (line 198)
Right hand side must be a dataset array.
Error in dataset/subsasgn (line 79)
a = subsasgnParens(a,s,b,creating);