필터 지우기
필터 지우기

How to Solve Mean of an Array? Show each Iteration?

조회 수: 2 (최근 30일)
CamLynn56
CamLynn56 2023년 2월 1일
답변: Sarthak 2023년 2월 9일
We were given the code shown below as a script and told to calculate Mean and to create a method to caalculate standard deviation. He wanted us to show each iteration and what each variable was equal to. I was confused on what he meant by this and what he watned us to do.
Clear All
x = [6 6 8 4 1 9 5];
N = length(x);
j=0;
Sum2=0;
V=zeros(1,N);
for i=1:N;
j=j+1;
Sum2=Sum2+x(i);
V(j)=Sum2;
end
MN=Sum2/N
  댓글 수: 1
Dyuman Joshi
Dyuman Joshi 2023년 2월 1일
"He wanted us to show each iteration and what each variable was equal to."
It would be better if you just ask your teacher/professor for some clarification, what they meant, rather than having us to speculate about it.

댓글을 달려면 로그인하십시오.

답변 (1개)

Sarthak
Sarthak 2023년 2월 9일
Hi,
If you just want to show what value each variable will hold as value after each iteration, you can just remove the semicolon at the end of the line in the ‘for’ loop. Else you can use the disp() function to display the value of each variable.

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

제품


릴리스

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by