Borrar filtros
Borrar filtros

Parse error at values

2 visualizaciones (últimos 30 días)
lopamudra singh
lopamudra singh el 30 de Oct. de 2020
Editada: Ameer Hamza el 1 de Nov. de 2020
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)

Respuestas (1)

Ameer Hamza
Ameer Hamza el 30 de Oct. de 2020
Editada: Ameer Hamza el 30 de Oct. de 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 comentarios
lopamudra singh
lopamudra singh el 1 de Nov. de 2020
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 el 1 de Nov. de 2020
Editada: Ameer Hamza el 1 de Nov. de 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

Iniciar sesión para comentar.

Categorías

Más información sobre MATLAB Compiler en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by