How to define a function

3 views (last 30 days)
Tiankang Xie
Tiankang Xie on 29 Sep 2015
Edited: Joseph Cheng on 29 Sep 2015
Hey guys. I am having a problem now and I really need help. I have to define a function which calculates the distance of a certain point from the center of the circle to determine is the point is in/on/outside of the circle. Suppose the radius is r, the center is (a,b). How can I use "If" and "return" to construct the problem? Thank you so much

Answers (1)

Joseph Cheng
Joseph Cheng on 29 Sep 2015
Edited: Joseph Cheng on 29 Sep 2015
check the documentation on functions http://www.mathworks.com/help/matlab/ref/function.html. after that it'll look something along the lines of
function output = yourfunction(a,b,r,x,y)
%calculate distance from (x,y) and (a,b)
%if statements to check if
%distance is == r
%elseif distance is <r
%elseif distance is >r
%return
I do not understand why you'd need a return statement

Community Treasure Hunt

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

Start Hunting!