채택된 답변

Alan Stevens
Alan Stevens 2021년 1월 13일

2 개 추천

Because the % symbol indicates that the rest of the line is a comment. So the only non comment parameter Matlab sees is the first 10.

댓글 수: 4

Yang Metin
Yang Metin 2021년 1월 13일
How should I enter? If 0.1 is not allowed
Daniel Pollard
Daniel Pollard 2021년 1월 13일
1/10
Alan Stevens
Alan Stevens 2021년 1월 13일
Seems crazy! However, how about
10/100
or define your own percent function, say
percent = @(x) x/100;
Steven Lord
Steven Lord 2021년 1월 13일
What do you mean by "How should I enter?" Where/how are you trying to enter this data?
Using the input function? If so accept the data as text, process that text, and finally convert that text into a number.
in = input("Enter the percentage discount: ", 's');
if endsWith(in, "%")
in = strip(in, "%");
end
inDouble = str2double(in)
Run this twice, the first time entering 10% at the prompt and the second time just entering 25.
In an inputdlg or an app? Get the data as text and proceed as I did with the input example above.
in = inputdlg("Enter the percentage discount")
In some other context like in a MATLAB script, function, or class file? If so please give more information.

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

추가 답변 (0개)

카테고리

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

태그

질문:

2021년 1월 13일

댓글:

2021년 1월 13일

Community Treasure Hunt

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

Start Hunting!

Translated by