Why am i recieving a "parse" error?

30 Ansichten (letzte 30 Tage)
Erin Cooper
Erin Cooper am 11 Feb. 2015
Beantwortet: Ankita Pawar am 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!

Akzeptierte Antwort

Roger Stafford
Roger Stafford am 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.

Weitere Antworten (1)

Ankita Pawar
Ankita Pawar am 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;

Kategorien

Mehr zu Entering Commands finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by