How do I make this script into a function?

%This program is a Slope Calculator.
%This program will calculate the slope in degrees from percent slope
disp('Would you like to calculate the internal angle?')
x = input('Please input rise/run as the gradient: ');
deg = (180/pi)*atan(x/100);
disp(deg)
end

답변 (1개)

Walter Roberson
Walter Roberson 2016년 11월 30일

0 개 추천

Just before all of that, add the line
function SlopeCalculator
where the word SlopeCalculator must be the same as the base name of the .m file it is stored in.

댓글 수: 2

M Pasanen
M Pasanen 2016년 11월 30일
Thanks! Doesn't it also need a function x= , or something like that as well ?
No. It is not required that functions return values.
If you happen to want to return deg then you could use
function deg = SlopeCalculator

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

카테고리

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

제품

질문:

2016년 11월 30일

댓글:

2016년 11월 30일

Community Treasure Hunt

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

Start Hunting!

Translated by