MATLAB: How can i write

.mnumberpromptsspecifiednumber

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

Best Answer

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.
Related Question