Writing a script that mirrors the abs function? I'm doing something wrong but not sure what

3 次查看(过去 30 天)
Here is the question:
The abs function finds the absolute value of a number or numbers in a matrix.
Using only relational operators and no built-in MATLAB functions, write a script
that recreates the abs function.
Here is what I did:
prompt='Enter a number';
x=input(x)
if x>0
disp(x)
elseif x<0
disp(x*(-1))
end
Help? Please?

回答(1 个)

the cyclist
the cyclist 2019-10-20
I think you meant
x=input(prompt)
  4 个评论

请先登录,再进行评论。

类别

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

Community Treasure Hunt

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

Start Hunting!

Translated by