function [m,s] = inputtrial(x)
n = length(x);
m = avg(x,n);
s = sqrt(sum((x-m).^2/n));
end
function m = avg(x,n)
m = sum(x)/n;
end
values[] = [12.7, 45.4, 98.9, 26.6, 53.1];
[ave,stdev] = inputtrial(values)

답변 (1개)

Ameer Hamza
Ameer Hamza 2020년 10월 30일
편집: Ameer Hamza 2020년 10월 30일

0 개 추천

In MATLAB, you can define an array like this
values = [12.7, 45.4, 98.9, 26.6, 53.1];
% values[] is a syntax error

댓글 수: 2

I've tried it also, but still showing error
function [m,s] = inputtrial(x)
n = length(x);
m = avg(x,n);
s = sqrt(sum((x-m).^2/n));
end
function m = avg(x,n)
m = sum(x)/n;
end
values = [12.7, 45.4, 98.9, 26.6, 53.1];
[ave,stdev] = inputtrial(values)
Error: File: inputtrial.m Line: 11 Column: 3
This statement is not inside any function.
(It follows the END that terminates the definition of the function "avg".)
Ameer Hamza
Ameer Hamza 2020년 11월 1일
편집: Ameer Hamza 2020년 11월 1일
In MATLAB, the lines of code must precede the function definitions. So move the last two lines to the top
values = [12.7, 45.4, 98.9, 26.6, 53.1];
[ave,stdev] = inputtrial(values)
function [m,s] = inputtrial(x)
n = length(x);
m = avg(x,n);
s = sqrt(sum((x-m).^2/n));
end
function m = avg(x,n)
m = sum(x)/n;
end

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

카테고리

도움말 센터File Exchange에서 MATLAB에 대해 자세히 알아보기

태그

질문:

2020년 10월 30일

편집:

2020년 11월 1일

Community Treasure Hunt

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

Start Hunting!

Translated by