matlab coding how to do this?
2 views (last 30 days)
Show older comments
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:
2 Comments
Rik
on 25 Nov 2021
Edited: Rik
on 25 Nov 2021
Why did you edit away your question? Were you afraid your teacher would find this question and consider this cheating?
Anyway, here is the original question:
matlab coding how to do this?
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:
Answers (2)
Image Analyst
on 24 Nov 2021
Hint:
% 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);
uiwait(warndlg(message));
end
if usersValue1 < 100
% code
elseif usersValue1 < 200
% code
end
etc.
3 Comments
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.
See Also
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!