2013-03-11 48 views
1

我写一个函数来对三行矩阵的每一行求和。下标索引必须是实数正整数或逻辑

然后使用有一行三列的矩阵来划分以前的结果。

但我不断收到该错误。我知道下标不应该是小数或负数。但我仍然无法找到罪魁祸首。请帮忙,谢谢。

% mean_access_time(ipinfo_dist, [306, 32, 192]) 
% 'ipinfo_dist' is a matrix which have three rows and column is not fixed. 

function result = mean_access_time(hash_mat, element_num) 
    access_time_sum = sum(rot90(hash_mat));  
    result = bsxfun (@rdivide, access_time_sum, element_num); 

例如:

A =

1 2 
3 4 
5 6 

B = 7 8 9

然后,我想获得

[(1+2)/7, (3+4)/8, (5+6)/9] 

更新:

>> which rot90 
/lou/matlab/toolbox/matlab/elmat/rot90.m 
>> which sum 
built-in (/lou/matlab/toolbox/matlab/datafun/@uint8/sum) % uint8 method 

罪魁祸首: 我用mean_access_time如前面的命令行的变量。

+1

是否有可能将'mean_access_time'用作脚本某处的变量名? – 2013-03-11 13:13:23

+0

@ H.Muster是的,你是对的。我在命令行中用它作为变量。我重新启动matlab。现在可以。谢谢 – louxiu 2013-03-11 13:16:27

+0

你的函数似乎是计算'sum(A,2)./ B''的复杂方法。注意应用于“B”的转置。 – 2013-03-11 13:19:42

回答

1

看起来好像你已经用变量名覆盖了一个内置函数(rot90sum)。

类型

>> dbstop if error 

并运行代码。

当错误发生时键入

K>> which rot90 
K>> which sum 

,如果你得到一个内置的函数或变量名见。

+0

谢谢,我粘贴我得到的。这样对吗? – louxiu 2013-03-11 13:11:13

+0

谢谢,我明白了。我在命令行中用它作为变量 – louxiu 2013-03-11 13:17:12

相关问题