If Statement
조회 수: 2 (최근 30일)
이전 댓글 표시
t=input('Enter a positive octal number')
if isnumeric(t)
s=num2str(t)
* if length*
disp([s ' is an invalid positive octal number'])
else
I am creating a octal to decimal calculator for class. We cannot use the one Matlab has installed. I have the rest of my code written but I am having trouble what my code should be at the beginning of my if statement. I know length is prompting for the array. I guess what I am asking is how would I write that part of the code to show if the number isnt a positive valid octal number
댓글 수: 1
Image Analyst
2011년 10월 28일
I don't know what you're asking. An valid octal number can be any length from one digit up to dozens or more. Do you really mean how can you scan it to make sure that only characters 0-7 are present in the user's entry?
답변 (1개)
Fangjun Jiang
2011년 10월 28일
For that, I think taking the input as a string is better.
t=input('Enter a positive octal number: ','s');
check=t>'0' & t<'7';
if ~all(check)
disp([t,' is an invalid positive octal number']);
end
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Matrix Indexing에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!