필터 지우기
필터 지우기

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 (최근 30일)
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?

채택된 답변

Image Analyst
Image Analyst 2015년 9월 26일
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.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Programming에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by