Error when computing the mean in Matlab

1 回表示 (過去 30 日間)
Maria
Maria 2014 年 8 月 8 日
コメント済み: Maria 2014 年 8 月 8 日
I have a double variable called Num_Firm_An with 3 columns and 60000 rows.
Num_Firm_An=[1994 12 19
1994 13 16
1994 16 12
1994 18 27
1994 19 15]
I tried the following two codes:
Code 1:
mean(Num_Firm_An(:,3))
Code 2:
year=1994:2013
for n=1:length(year)
NFA=Num_Firm_An(Num_Firm_An(:,1)==year(n),:);
m=mean(NFA(:,3));
s=std(NFA(:,3));
NFAmean{n}=m;
NFAstd{n}=s;
end
Code one gives the overall mean throughout the years. Code two should provide a final variable with both means and standard deviations for all the years.
Both codes are giving me the follwoing error: Index exceeds matrix dimensions. And I am not being able to solve it. Can someone help me? Thanks

採用された回答

Azzi Abdelmalek
Azzi Abdelmalek 2014 年 8 月 8 日
mean([Num_Firm_An{:,3}])
  6 件のコメント
Azzi Abdelmalek
Azzi Abdelmalek 2014 年 8 月 8 日
If your variable is double, your code is correct. But maybe, you have used the function mean as a variable in your code, rename this variable and try again.
You can check if the variable mean was used ( whos mean)
Try this
clear mean,% to clear the variable mean, you will be able to call the function mean
Num_Firm_An=[1994 12 19
1994 13 16
1994 16 12
1994 18 27
1994 19 15]
mean(Num_Firm_An(:,3))
Maria
Maria 2014 年 8 月 8 日
you are so right. I had a variable called mean that I had created by mistake. Sorry for the time. Thank you so much

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeData Type Identification についてさらに検索

製品


Translated by