필터 지우기
필터 지우기

Need help debugging code

조회 수: 2 (최근 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 CenterFile Exchange에서 Logical에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by