Why am i recieving a "parse" error?
30 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Erin Cooper
el 11 de Feb. de 2015
Respondida: Ankita Pawar
el 10 de Sept. de 2019
I am trying to write a very simple function file to use in my more complicated script file. The file I have is this:
>function y(x)=trigC(x)
>>>y(x)=(cos(5*x))
>end
When I do this, the error within the function says "Parse error at '=': usage might be invalid MATLAB synax" referring to the y(x)=trigC(x). And when I run the program it says "The expression to the left of the equals sign is not a valid target for an assignment."
I am not familiar enough with MATLAB syntax to figure out what it even means, let alone how to fix it. Any ideas? Thank you!
0 comentarios
Respuesta aceptada
Roger Stafford
el 12 de Feb. de 2015
You can't write your function that way. Write it this way:
function y = trigC(x)
y = cos(5*x);
end
Because of the nature of the 'cos' function, if x is a vector of values, then y will return as a similar size vector of the cosine of five times the corresponding values in x. A similar statement holds if x is a scalar or an n-dimensional array.
Más respuestas (1)
Ankita Pawar
el 10 de Sept. de 2019
i am trying to write this function but parse error occure near '=' this .
please tell me what is the wrong in it.
machine1
en:
switch = 1;
stack_m = 1;
stack_l = 1;
sensor_m1 = 1;
sensor_m2 = 1;
sensor_l1 = 1;
sensor_l2 = 1;
exit:
m = 1;
0 comentarios
Ver también
Categorías
Más información sobre Entering Commands en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!