首页 > 解决方案 > rowfun 错误“输入参数过多”

问题描述

为什么这个匿名函数不能使用rowfun

>> T = table([43;52;67;28],[64;24;69;45])
>> rowfun(@(x) sum(x), T)

Error using tabular/rowfun>dfltErrHandler (line 497)
Applying the function '@(x)sum(x)' to the 1st row of A generated the following
error:

Too many input arguments.

标签: matlab

解决方案


您要在此处执行的操作是plus,而不是sum匿名函数应该有两个输入,即

rowfun(@(x,y) plus(x,y), T)

这也相当于:

rowfun(@plus, T)

输出:

ans =    
  4×1 table

    Var1
    ____

    107 
     76 
    136 
     73 

推荐阅读