Hi, I am very new to matlab, this is actually the first time I am using it. I have to write a code for finding averages, right now I have "function av=average(x1,x2,x3,x4,x5)(adsbygoogle = window.adsbygoogle || []).push({});

% average(x1,x2,x3,x4,x5) returns the average of (x1,x2,x3,x4,x5)

av=(x1+x2+x3+x4+x5)/5;

return;"

This works just fine when there are 5 things to average, but I can't figure out how to make it work for n variables. Can someone help me please?

**Physics Forums | Science Articles, Homework Help, Discussion**

The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

# Homework Help: Writing a code in matlab for n variables.

**Physics Forums | Science Articles, Homework Help, Discussion**