how to change it?
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Shi Yuhao
el 5 de Mayo de 2014
Comentada: Shi Yuhao
el 5 de Mayo de 2014
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?
0 comentarios
Respuesta aceptada
Mischa Kim
el 5 de Mayo de 2014
Editada: Mischa Kim
el 5 de Mayo de 2014
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 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Workspace Variables and MAT-Files en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!