1

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);

For example:

A=

1 2 
3 4
5 6

B= 7 8 9

Then I want to get

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

Update:

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

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

Shai
  • 111,146
  • 38
  • 238
  • 371
louxiu
  • 2,830
  • 3
  • 28
  • 42
  • 1
    Is it possible that you used `mean_access_time` as a variable name somewhere in your script? – H.Muster Mar 11 '13 at 13:13
  • @H.Muster Yeah, you are right. I used it as variable in the command line. I restart the matlab. It is OK now. Thanks – louxiu Mar 11 '13 at 13:16
  • Your function seems to be a complicated way to calculate `sum(A,2)./B'`. Note the transposition applied to `B`. – High Performance Mark Mar 11 '13 at 13:19
  • Also see [this question](http://stackoverflow.com/questions/20054047/subscript-indices-must-either-be-real-positive-integers-or-logicals-generic-sol) for [the generic solution to this problem](http://stackoverflow.com/a/20054048/983722). – Dennis Jaheruddin Nov 27 '13 at 15:42

1 Answers1

1

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

Type

>> dbstop if error

And run your code.

When the error occurs type

K>> which rot90
K>> which sum

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

Shai
  • 111,146
  • 38
  • 238
  • 371