Parse error at values
2 views (last 30 days)
Show older comments
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)
0 Comments
Answers (1)
Ameer Hamza
on 30 Oct 2020
Edited: Ameer Hamza
on 30 Oct 2020
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 Comments
Ameer Hamza
on 1 Nov 2020
Edited: Ameer Hamza
on 1 Nov 2020
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
See Also
Categories
Find more on MATLAB Compiler in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!