如何在Matlab统计工具箱中分配数据集的单个元素?

时间:2013-08-02 18:47:08

标签: matlab statistics

在下面的示例中,如何将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); 

1 个答案:

答案 0 :(得分:1)

找到它:带括号:

>> ds{2,'Age'}=40
ds = 
            Age
    John    30 
    Anne    40