필터 지우기
필터 지우기

I have a variance question, however, my code isn't bringing up this in the command window when i try to run it. "Function definition are not supported in this context".

조회 수: 2 (최근 30일)
function s2 = samplevar(x)
n=length(x); %sample size
q=mean(x);% mean of vector
for x=2:n
s2= sum((x-q)^2)/(n-1); formula for sample variance
end
x =[3,5,6,7,8,10]; example of a vector
samplevar(x) output
end

채택된 답변

Dyuman Joshi
Dyuman Joshi 2023년 9월 14일
This section should not be a part of the function definition. Use this section to call the function from the command window/line.
x =[3,5,6,7,8,10]; %example of a vector
%Function call
y = samplevar(x)
y = 0.0500
%This section is for the definition of the function
function s2 = samplevar(x)
n=length(x); %sample size
q=mean(x);% mean of vector
for x=2:n
s2= sum((x-q)^2)/(n-1); %formula for sample variance
end
end

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Multirate Signal Processing에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by