Why am i recieving a "parse" error?
30 ビュー (過去 30 日間)
古いコメントを表示
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 件のコメント
採用された回答
Roger Stafford
2015 年 2 月 12 日
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.
その他の回答 (1 件)
Ankita Pawar
2019 年 9 月 10 日
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 件のコメント
参考
カテゴリ
Help Center および File Exchange で Entering Commands についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!