MATLAB how to use a forloop to iterate through these 6 array

MATLAB: how to use a for-loop to iterate through these 6 arrays. create another array to hold average of each array

such as:

newArray (1) should be avg of player1

newArray (2) should be avg of player2

player1= [91 89 90 90 85 87 95 81 91 891 ; player2= [85 83 83 88 80 85 85 90 86 87]; player3= [79 78 85 76 79 75 74 77 75 78]; player4= [82 80 82 82 87 79 81 80 81 84 ] ; player5= [95 98 94 95 97 98 99 97 99 96]; player6= [74 77 78 73 71 75 75 71 73 80];

Solution

newArray = {};

sum =0

for k =1 : length(player1);

      sum = sum + player1(k)

newArray = [newArray sum]

sum =0

for k =1 : length(player2);

      sum = sum + player2(k)

newArray = [newArray sum]

sum =0

for k =1 : length(player3);

      sum = sum + player3(k)

newArray = [newArray sum]

sum =0

for k =1 : length(player4);

      sum = sum + player4(k)

newArray = [newArray sum]

sum =0

for k =1 : length(player5);

      sum = sum + player5(k)

newArray = [newArray sum]

sum =0

for k =1 : length(player6);

      sum = sum + player6(k)

newArray = [newArray sum]

MATLAB: how to use a for-loop to iterate through these 6 arrays. create another array to hold average of each array such as: newArray (1) should be avg of playe

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site