how can i write

2 visualizaciones (últimos 30 días)
nil co
nil co el 27 de Dic. de 2015
Comentada: Image Analyst el 27 de Dic. de 2015
Write a program that prompts the user to enter an integer from 1 to 8. If the user enters a number different than specified numbers, request the user to enter again until the number entered is in range 1 to 8. The number entered by the user specifies the number of rows printed and your program should give the following output: Using array(matrix) is not allowed

Respuesta aceptada

Image Analyst
Image Analyst el 27 de Dic. de 2015
Here's a snippet I've posted many times, and I've added a few lines at the bottom to get you started.
% Ask user for an integer number.
defaultValue = 45;
titleBar = 'Enter an integer value';
userPrompt = 'Enter the integer';
caUserInput = inputdlg(userPrompt, titleBar, 1, {num2str(defaultValue)});
if isempty(caUserInput),return,end; % Bail out if they clicked Cancel.
% Round to nearest integer in case they entered a floating point number.
integerValue = round(str2double(cell2mat(caUserInput)));
% Check for a valid integer.
if isnan(integerValue)
% They didn't enter a number.
% They clicked Cancel, or entered a character, symbols, or something else not allowed.
integerValue = defaultValue;
message = sprintf('I said it had to be an integer.\nI will use %d and continue.', integerValue);
uiwait(warndlg(message));
end
desiredNumbers = [................
if ismember(integerValue, desiredNumbers)..............
You could also use "if ~isempty(ismember(................." instead if you want.
  2 comentarios
nil co
nil co el 27 de Dic. de 2015
g
Image Analyst
Image Analyst el 27 de Dic. de 2015
What is this?
Why did you post this screenshot?

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Logical 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!

Translated by