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일

1 개 추천

mean([Num_Firm_An{:,3}])

댓글 수: 6

Maria
Maria 2014년 8월 8일
It gives this error now: Cell contents reference from a non-cell array object.
Make sure you have the same brackets everywhere maybe. [ straight ] vs { curly }
I copy pasted your code as well as Azzi's, and received no error.
Maria
Maria 2014년 8월 8일
I am trying different options and I always get an error. Do you think it's maybe because my variable it's a double?
Maria, [1 2] is a double array, {1 2} is a cell array. What do you have, double or cell array?
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개)

카테고리

도움말 센터File Exchange에서 Data Type Identification에 대해 자세히 알아보기

제품

질문:

2014년 8월 8일

댓글:

2014년 8월 8일

Community Treasure Hunt

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

Start Hunting!

Translated by