下标索引必须是实数正整数或逻辑值 [英] Subscript indices must either be real positive integers or logicals

查看:133
本文介绍了下标索引必须是实数正整数或逻辑值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我编写了一个函数,对具有三行的矩阵的每一行求和.

I write a function to sum each row of a matrix which have three rows.

然后使用具有一行和三列的矩阵来划分前一个结果.

Then use a matrix which have one row and three columns to divide the previous result.

但是我不断收到该错误.我知道下标不应为十进制或负数.但是我仍然找不到罪魁祸首.请帮忙,谢谢.

But I keep getting that error. I know the subscript should not be a decimal or negative number. But I still can not find the culprit. Please help, thanks.

% 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

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用作变量.

Culprit: I used mean_access_time as a variable in the previous command line.

推荐答案

似乎您已用变量名覆盖了内置函数(rot90sum).

It seems like you have overridden a built-in function ( rot90 or sum ) with variable name.

类型

>> dbstop if error

然后运行您的代码.

发生错误时,键入

K>> which rot90
K>> which sum

查看您是否获得内置函数或变量名.

See if you get a built-in function or a variable name.

这篇关于下标索引必须是实数正整数或逻辑值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆