How i Calculate the average number of even numbers in an array?
19 views (last 30 days)
More Answers (2)
Kevin Chng on 4 Dec 2018
My answer is
Check the index of Even number first
a = [1.3700 1.2200 2.2000 2.2800];
index = mod(single(a*100),2)==0;
Calculate the mean value of Even Number in the array
GT on 4 Dec 2018
I am not sure if I understand your question correctly.
In MATLAB to calculate the average you would use the function: mean
In your example:
a = [1.37 1.22 2.20 2.28];
yourAverage = mean(a)
Please note in your question you asked about odd number. You could do:
This is adding the last 3 elements of the array a, and dividing by 3 as you illustrated, but there is something not right with your Maths... as:
(1.22+2.22+2.28)/3 is not 4.2.
Hope this helps.