I really need help on conditonal statements. Can someone help me get started on this question please. Would really appreciate it, I'm new to matlab, and trying to really understand it.

4 views (last 30 days)
I finished the first two, I just need help on question 3. Im struggling to get started, and also do i need an if statement for each temperature and pressure scenario?

Accepted Answer

Image Analyst
Image Analyst on 26 Sep 2015
Hint:
To print to command line:
fprintf('The temperature = %f\nThe pressure = %f\n', temperature, pressure);
To set a category, I'd set a category as a number for each:
if temperature > 355
tempCat = 5;
elseif tempreature > 345 && temperature <= 355
tempCat = 4;
and so on. Do the same for the pressure. Then to set the overall category as the max of the pressure and temp category, do this:
overallCategory = max([tempCat, pressureCat]);
Then have an if/else where you check the overall category
if overallCategory == 5
fprintf('Very Severe\n');
elseif overallCategory == 4
fprintf(
and so on. Here's a snippet of code to ask for two numbers that is more user friendly than input():
% Ask user for two floating point numbers.
defaultValue = {'45.67', '78.91'};
titleBar = 'Enter a value';
userPrompt = {'Enter temperature : ', 'Enter pressure '};
caUserInput = inputdlg(userPrompt, titleBar, 1, defaultValue);
if isempty(caUserInput),return,end; % Bail out if they clicked Cancel.
% Convert to floating point from string.
temperature = str2double(caUserInput{1})
pressure= str2double(caUserInput{2})
% Check for a valid number.
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.
temperature = str2double(defaultValue{1});
message = sprintf('I said it had to be a number.\nI will use %.2f and continue.', usersValue1);
uiwait(warndlg(message));
end
and so on.

More Answers (0)

Categories

Find more on Programming in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!