2013-08-02 70 views
0

在下面的例子中,如何將Ann的年齡設置爲40?如何在Matlab統計工具箱中指定數據集的單個元素?

>> 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); 

回答

1

發現:用大括號:

>> ds{2,'Age'}=40 
ds = 
      Age 
    John 30 
    Anne 40 
相關問題