Need help debugging code

1 回表示 (過去 30 日間)
Brendan Jozwiak
Brendan Jozwiak 2022 年 10 月 26 日
回答済み: Steven Lord 2022 年 10 月 27 日
Question I am trying to code :
  1. (20 pts)Write a function named matAvg that will receive a matrix matas given below as an input argument and will calculate and return the overall average of all numbers in the matrix. Use for loops (not built-in functions) to calculate the average. Given
mat = [6 9 7 3; 7 3 0 1; 4 8 1 1; 6 2 2 5]
You should be able to invoke the function from command prompt as
>>avg = matAvg(mat)
SAMPLE OUTPUT
mat =
6 9 7 3
7 3 0 1
4 8 1 1
6 2 2 5
avg =
4.0625
My code:
How the code is supposed to turn out:

採用された回答

Torsten
Torsten 2022 年 10 月 27 日
移動済み: Voss 2022 年 10 月 27 日
Your input matrix is missing in the call.
  2 件のコメント
Brendan Jozwiak
Brendan Jozwiak 2022 年 10 月 27 日
移動済み: Voss 2022 年 10 月 27 日
how would I fix this?
Brendan Jozwiak
Brendan Jozwiak 2022 年 10 月 27 日
移動済み: Voss 2022 年 10 月 27 日
never mind got it thank you for the help

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

その他の回答 (1 件)

Steven Lord
Steven Lord 2022 年 10 月 27 日
Look at how you call your function in your Command Window and look how the example calls it in the sample output. You're not calling it the same way the example does.
How should MATLAB know which matrix it should operate on with your function call? Did you tell it?

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by