How do I make this script into a function?

1 次查看(过去 30 天)
%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
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 ?
Walter Roberson
Walter Roberson 2016-11-30
No. It is not required that functions return values.
If you happen to want to return deg then you could use
function deg = SlopeCalculator

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Programming 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by