【问题标题】:MATLAB: Last row in a matrix is not computing :(MATLAB:矩阵中的最后一行不计算:(
【发布时间】:2017-11-27 00:16:57
【问题描述】:

所以我有一个同质数值数组,如下所示。我使用 array2Table 函数将此数组转换为表。下面显示的只是应用于数组的变量名称。我有列名,但我也想有行名。数组是一个变量类,我不能这样做吗?

T = array2table(C,'RowNames',{'','T0','T1','T2','T3','T4'},'VariableNames' ,{'to','t1','t2','t3','t4','t5','t6','t7','t8','t9','t10'})




T =

  6×11 table

    to       t1        t2        t3        t4        t5        t6        t7        t8        t9       t10  
    ___    ______    ______    ______    ______    ______    ______    ______    ______    ______    ______

      0        18        36        54        72        90       108       126       144       162       180
     15        15        15        15        15        15        15        15        15        15        15
    325    304.17     303.4    295.01    293.52     288.3    286.56    282.49     280.5    276.99     274.8
    325       325    315.67    314.35    308.58    306.86    302.38    300.33    296.49    294.19    290.74
    325       325       325    320.82     319.8    315.43    313.61    309.61    307.35    303.69     301.2
    325       325       325       325    321.25    319.95     315.9    313.85    310.05    307.63     304.1

我在这里遇到的错误是:

Error using matlab.internal.tabular.private.rowNamesDim/validateAndAssignLabels (line 109)
The RowNames property must be a cell array, with each element containing one nonempty character vector.

Error in matlab.internal.tabular.private.tabularDimension/setLabels (line 173)
            obj = obj.validateAndAssignLabels(newLabels,indices,fullAssignment,fixDups,fixEmpties,fixIllegal);

Error in matlab.internal.tabular.private.tabularDimension/createLike_impl (line 355)
                obj = obj.setLabels(dimLabels,[]);

Error in matlab.internal.tabular.private.tabularDimension/createLike (line 62)
                obj = obj.createLike_impl(dimLength,dimLabels);

Error in tabular/initInternals (line 206)
            t.rowDim = t.rowDim.createLike(nrows,rowLabels);

Error in table.init (line 327)
            t = initInternals(t, vars, numRows, rowLabels, numVars, varnames);

Error in array2table (line 64)
    t = table.init(vars,nrows,rownames,nvars,varnames);

【问题讨论】:

  • 忽略标题,我在重写我的问题时忘记更改它:(
  • 你数组的第一个元素是空字符向量,你得到的错误清楚地表明The RowNames property must be a cell array, with each element containing one nonempty character vector.
  • @Vonny 不要告诉我们忽略标题,而是将标题编辑为应有的样子。

标签: matlab for-loop if-statement matrix


【解决方案1】:

你得到的错误是

RowNames 属性必须是一个元胞数组,每个元素都包含一个非空字符向量。

这是一个有效的版本:

T = array2table(C,'RowNames',{'T','T0','T1','T2','T3','T4'},'VariableNames' ,{'to','t1','t2','t3','t4','t5','t6','t7','t8','t9','t10'})

您需要将RowNames 数组的第一个元素更改为非空字符向量,例如'T' 而不是 ''

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-05-19
    • 1970-01-01
    • 2020-07-09
    • 1970-01-01
    • 1970-01-01
    • 2012-05-25
    • 1970-01-01
    相关资源
    最近更新 更多