MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn moreOpportunities for recent engineering grads.

Apply Today**New to MATLAB?**

Asked by eren eren
on 6 Dec 2012

top2=0;top3=0; mij=ones(5,5); mi=ones(1,5); X=[242 183 237 141 125;157 181 268 232 220;219 185 151 261 120;331 151 239 203 206;138 213 222 174 189]; Xort=mean(X); %mean for rows for i=1:5 n(i)=length(X); end for i=1:5 for j=1:5 top2=top2+(mij(i,j)*(X(i,j)-Xort(i))^2) %top is in english sum. share % fraction for v end top3=top3+(n(i)-1); % denominator of v fraction end v=top2/top3;% v is the estimate which i want to calculate v

**İn this program, result is v =3.6694e+003 but it is wrong.in for loop only i=1 and j=1 works correctly. if i=1 j=2, results are bad. Can you help me?**

*No products are associated with this question.*

## 11 Comments

## Thomas (view profile)

Direct link to this comment:http://www.mathworks.com/matlabcentral/answers/55896#comment_115694

What results do you expect?

## eren eren (view profile)

Direct link to this comment:http://www.mathworks.com/matlabcentral/answers/55896#comment_115771

i expect around 3500

## Sean de Wolski (view profile)

Direct link to this comment:http://www.mathworks.com/matlabcentral/answers/55896#comment_115772

Well 3669.4 isn't that far away. Are you sure it's wrong?

## Walter Roberson (view profile)

Direct link to this comment:http://www.mathworks.com/matlabcentral/answers/55896#comment_115773

To check: you are aware that mean(X) is mean(X,1) which is to say mean down the columns? mean(X,2) would be across the rows. Checking to see if you intend rows or columns ?

## Image Analyst (view profile)

Direct link to this comment:http://www.mathworks.com/matlabcentral/answers/55896#comment_115778

Can you tell us in words, or can you put in some English comments that say what this does? What is the overall goal of this? What do top2 and top3 and their ratio represent? Maybe there's a simpler way, like using conv2() or something. Also, do you know that length(X) for a 2 D array is the length of the longest dimension (not the number of elements, which is numel(), or the width or height of the array)? I think it's rare to see length() used on a 2D array.

## eren eren (view profile)

Direct link to this comment:http://www.mathworks.com/matlabcentral/answers/55896#comment_115944

i expect around 3500 but not e+003. Can i get rid of e+.

for x(1,1), it returns right result but for x(1,2) and after it returns e+ value. i don't want this.

i edited my first message and added some comments.

## Walter Roberson (view profile)

Direct link to this comment:http://www.mathworks.com/matlabcentral/answers/55896#comment_115945

Give the command

and then display the result

## eren eren (view profile)

Direct link to this comment:http://www.mathworks.com/matlabcentral/answers/55896#comment_115962

Please be more specific. where do i give format long g command ???

## Matt Fig (view profile)

Direct link to this comment:http://www.mathworks.com/matlabcentral/answers/55896#comment_115963

At the command line

## eren eren (view profile)

Direct link to this comment:http://www.mathworks.com/matlabcentral/answers/55896#comment_116070

Thanks Walter Roberson. This is working. do i use it every time or is it only one?

## Walter Roberson (view profile)

Direct link to this comment:http://www.mathworks.com/matlabcentral/answers/55896#comment_116085

Have it once in your program.