Need help debugging code
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Brendan Jozwiak
am 26 Okt. 2022
Beantwortet: Steven Lord
am 27 Okt. 2022
Question I am trying to code :
- (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:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1170478/image.png)
How the code is supposed to turn out:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1170483/image.jpeg)
0 Kommentare
Akzeptierte Antwort
Weitere Antworten (1)
Steven Lord
am 27 Okt. 2022
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?
0 Kommentare
Siehe auch
Kategorien
Mehr zu Logical finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!