Error while computing mean of a row vector

I am getting the following error while finding out the mean of a row vector(using the mean function of matlab) containing ten elements:
Subscript indices must either be real positive integers or logicals.
Could any one tell me how to resolve this error?
Thank you!

 採用された回答

Star Strider
Star Strider 2015 年 8 月 19 日

0 投票

In the Command Window, type:
which mean -all
If it returns:
mean is a variable.
among its path returns, you are ‘shadowing’ (or ‘overshadowing’) the mean function with a variable you named ‘mean’. The solution is to rename the variable to ‘meanx’ or some such.

5 件のコメント

rihab
rihab 2015 年 8 月 19 日
Well I haven't named the variable 'mean'; for example
xy = mean(abc) %abc is a row vector; abc=15.4206*ones(1,10)
and the error is:
Subscript indices must either be real positive integers or logicals.
Star Strider
Star Strider 2015 年 8 月 19 日
This works for me without error:
abc=15.4206*ones(1,10);
xy = mean(abc);
I still suspect somewhere in your code, either mean or ones (if that is actually your code) are being shadowed. I would imagine you could get a ‘index exceeds matrix dimension’ error with positive integer arguments, but since they aren’t integers, you’re getting the error you see.
Stephen23
Stephen23 2015 年 8 月 19 日
@anuribs: please tell us exactly the output when you run this command:
which mean -all
rihab
rihab 2015 年 8 月 20 日
I am getting the same error: Subscript indices must either be real positive integers or logicals.
But now I am calculating it in the traditional way,i.e taking the sum and dividing it by the total number of observations so no longer a problem for me!
Star Strider
Star Strider 2015 年 8 月 20 日
I still believe you’re shadowing the mean function somewhere in your code.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeCreating and Concatenating Matrices についてさらに検索

質問済み:

2015 年 8 月 19 日

コメント済み:

2015 年 8 月 20 日

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by