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 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Muhideen Ogunlowo
am 14 Sep. 2023
Bearbeitet: Walter Roberson
am 14 Sep. 2023
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
0 Kommentare
Akzeptierte Antwort
Dyuman Joshi
am 14 Sep. 2023
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)
%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
Read more here - https://in.mathworks.com/help/matlab/ref/function.html
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Multirate Signal Processing 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!