필터 지우기
필터 지우기

How do I Run the below program? The sample program sums various column vectors. How do I Modify the first of the program (i.e., ignore the xsum2part) to calculate averages.

조회 수: 1 (최근 30일)
x=[1;2;7;5;9;3;6;9;1;11;1];
xsum=sum(x);
xsum1=0;
for i=1:11
xsum1=xsum1 + x(i,1);
end
disp xsum;
disp(xsum);
disp xsum1;
disp(xsum1);
xsum2=0;
for i=1:11
if x(i,1)> 4
xsum2=xsum2 + x(i,1);
end
2
end
disp xsum2
disp(xsum2);
  댓글 수: 1
Mathieu NOE
Mathieu NOE 2021년 9월 3일
hello
why not using mean with the correct dimensions
help mean
mean Average or mean value.
S = mean(X) is the mean value of the elements in X if X is a vector.
For matrices, S is a row vector containing the mean value of each
column.
For N-D arrays, S is the mean value of the elements along the first
array dimension whose size does not equal 1.
mean(X,'all') is the mean of all elements in X.
mean(X,DIM) takes the mean along the dimension DIM of X.
mean(X,VECDIM) operates on the dimensions specified in the vector
VECDIM. For example, mean(X,[1 2]) operates on the elements contained
in the first and second dimensions of X.

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

답변 (1개)

Prince Kumar
Prince Kumar 2021년 9월 6일
You can use "mean" function to find the average. Please have a look at the code below :
x=[1;2;7;5;9;3;6;9;1;11;1];
avg = mean(x);
disp(avg);
Please refer the document for information : mean

카테고리

Help CenterFile Exchange에서 Time Series에 대해 자세히 알아보기

제품


릴리스

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by