i =0;
while (i<10)
i = i+1;
x = input('enter the number');
if isreal(x)
if isinteger(x)
end
end
if (x>255)
disp('"error:Value too big."')
else if ((x>=0) && (x<=255))
disp('<x>')
else
disp('-1')
end
end
end
What's wrong with this script? In command window, it appear the letter <x>. But I want to get the input number of x. Besides, it can only do it 10 times whatever the number I input. I expect it can work during the range 0-255 10 times. How to change it?

 채택된 답변

Mischa Kim
Mischa Kim 2014년 5월 5일
편집: Mischa Kim 2014년 5월 5일

0 개 추천

Shi, check out
fileID = fopen('num.txt','w');
while (i<10)
x = input('enter the number: ');
if isreal(x) % no action?
if isinteger(x) % no action?
end
end
if (x>255)
disp('"error:Value too big."');
elseif ((x>=0) && (x<=255))
disp(['<',num2str(x),'>']); % display the value of x
i = i+1; % increment i if x in range
fprintf(fileID,'%d\n',x);
else
disp('-1'); % display string '-1'
end
end
fclose(fileID);

댓글 수: 3

Shi Yuhao
Shi Yuhao 2014년 5월 5일
편집: Shi Yuhao 2014년 5월 5일
I want to add the <>between my output result. I dong't know what I should say in action.If it is a real number, it should go on the script.Else, it should be rejected. The same to integer. What should I do about it? How to add a file to save all the elements?
Mischa Kim
Mischa Kim 2014년 5월 5일
See above.
Shi Yuhao
Shi Yuhao 2014년 5월 5일
Thank you! I get it.

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

추가 답변 (0개)

카테고리

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

질문:

2014년 5월 5일

댓글:

2014년 5월 5일

Community Treasure Hunt

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

Start Hunting!

Translated by