Average without direct commands

2 ビュー (過去 30 日間)
Gina Barlage
Gina Barlage 2015 年 5 月 19 日
編集済み: per isakson 2015 年 5 月 19 日
My assignment is to create a script where when I put a string of numbers into the command window and run the script it will calculate the average of the string of numbers. I am not permitted to use sum or mean in the script. What kind of script would I write? A loop?
  1 件のコメント
per isakson
per isakson 2015 年 5 月 19 日
What you done so far?

サインインしてコメントする。

回答 (2 件)

Image Analyst
Image Analyst 2015 年 5 月 19 日
The numbers in the command window would have to be assigned to some variable. Then your script can use a for loop to add all the elements of that variable together.

Murali Krishna
Murali Krishna 2015 年 5 月 19 日
編集済み: per isakson 2015 年 5 月 19 日
try this...
b=0;
l=length(a);
for k=1:l
b=b+a(k);
end
m=b/l;
input the string of numbers as a in the command window

カテゴリ

Help Center および File ExchangeData Type Identification についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by