【问题标题】:How to assign to a single element of dataset in Matlab statistics toolbox?如何在 Matlab 统计工具箱中分配给数据集的单个元素?
【发布时间】:2013-08-02 18:47:07
【问题描述】:

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

【问题讨论】:

    标签: matlab statistics


    【解决方案1】:

    找到它:带大括号:

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

    【讨论】:

      猜你喜欢
      • 2011-02-12
      • 1970-01-01
      • 2013-06-10
      • 2011-09-13
      • 1970-01-01
      • 2013-02-08
      • 2016-06-26
      • 1970-01-01
      • 2015-09-24
      相关资源
      最近更新 更多