Question: Write a function that takes a vector as input and returns the average of all the positive numbers that are multiples of 7 My current

Write a function that takes a vector as input and returns the average of all the positive numbers that are multiples of 7

My current code is

function avg = avgpositive7multiples_for(x);

positive = x(x>=0);

y = sum(positive(find(mod(positive, 7)==0)));

a = numel(find((mod(positive, 7)==0)));

avg = y/a;

but i have to use a for loop for this problem and I am unsure of how to convert it

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!