How to define a function

조회 수: 2 (최근 30일)
Tiankang Xie
Tiankang Xie 2015년 9월 29일
편집: Joseph Cheng 2015년 9월 29일
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

답변 (1개)

Joseph Cheng
Joseph Cheng 2015년 9월 29일
편집: Joseph Cheng 2015년 9월 29일
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

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by