Function M-Files Help

I am a first time MATLAB user and to be honest, am really struggling. So if anyone could help break this down for me into small, easy steps, it would be very appreciated.
I am trying to create a function m-file. But before I went to the specific problem, I used a test code I found to get the hang of what I was supposed to be doing. (The example was found online and copied down to test).
This is my code:
function y = dude(x)
y = x.^2 + cos(x);
However, MATLAB is telling me there is an invalid statement. It is the exact same code as the example and there are no warnings found in the program. Is there something that I am overlooking?

 채택된 답변

Azzi Abdelmalek
Azzi Abdelmalek 2012년 10월 13일

0 개 추천

your code is fine, maybe you did'nt call the function correctly
example, to call your function, go to matlab command, then
y = dude(4)
%or
y=dude([1 4 5])

댓글 수: 2

Annie
Annie 2012년 10월 13일
When I do so, I get the error:
Undefined function 'dude' for input arguments of type 'double'.
Azzi Abdelmalek
Azzi Abdelmalek 2012년 10월 13일
check if your file is saved in your working path

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Annie
Annie 2012년 10월 13일

0 개 추천

When I do so, I get the error:
Undefined function 'dude' for input arguments of type 'double'.

카테고리

도움말 센터File Exchange에서 Cell Arrays에 대해 자세히 알아보기

질문:

2012년 10월 13일

Community Treasure Hunt

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

Start Hunting!

Translated by