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

조회 수: 4 (최근 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일
In the future, it's best to include the complete error message that you are seeing. Also, I used the CODE icon to format your code.

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

답변 (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