Why am i recieving a "parse" error?
30 views (last 30 days)
Show older comments
Erin Cooper
on 11 Feb 2015
Answered: Ankita Pawar
on 10 Sep 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 Comments
Accepted Answer
Roger Stafford
on 12 Feb 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.
More Answers (1)
Ankita Pawar
on 10 Sep 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 Comments
See Also
Categories
Find more on Entering Commands in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!