Filter löschen
Filter löschen

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.

3 Ansichten (letzte 30 Tage)
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?

Akzeptierte Antwort

Image Analyst
Image Analyst am 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.

Weitere Antworten (0)

Kategorien

Mehr zu Programming finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by