matlab coding how to do this?

4 views (last 30 days)
Lanya Patel
Lanya Patel on 24 Nov 2021
Commented: Rena Berman on 13 Dec 2021
Task 3: Another simple script file Write a Matlab script file to do the following:
Accept a number from the user.
If the number entered is less than 100 then displays the message “Number is less than 100”, and print the number entered.
If the number entered lies between [100, 200] inclusive then displays the message “Number lies between 100 and 200”, and print the number entered. •
If the number entered is greater than 200 then displays the message “Number greater than 200”, and print the number entered. A possible Matlab session calling the script file may looks like the following:
Rena Berman
Rena Berman on 13 Dec 2021

(Answers Dev) Restored edit

Sign in to comment.

Answers (2)

Rik on 24 Nov 2021
doc input
doc if

Image Analyst
Image Analyst on 24 Nov 2021
% Ask user for two floating point numbers.
defaultValue = {'400'};
titleBar = 'Enter values';
userPrompt = {'Enter floating point number 1 : '};
caUserInput = inputdlg(userPrompt, titleBar, 1, defaultValue);
if isempty(caUserInput),return,end % Bail out if they clicked Cancel.
% Convert to floating point from string.
usersValue1 = str2double(caUserInput{1})
% Check usersValue1 for validity.
if isnan(usersValue1)
% They didn't enter a number.
% They clicked Cancel, or entered a character, symbols, or something else not allowed.
% Convert the default from a string and stick that into usersValue1.
usersValue1 = str2double(defaultValue{1});
message = sprintf('I said it had to be a number.\nTry replacing the user.\nI will use %.2f and continue.', usersValue1);
if usersValue1 < 100
% code
elseif usersValue1 < 200
% code
Image Analyst
Image Analyst on 24 Nov 2021
How much of your homework are we allowed to do? All of it? I'm afraid if I do more then you'd get in trouble for copying someone elses code and turning it in as your own.
Actually you just deleted your question and I don't remember what it was anymore.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!