필터 지우기
필터 지우기

I have no idea how to even approach this set of commands I am asked to execute. Any help will be amazing.

조회 수: 1 (최근 30일)
1.) Create a program that prompts the user to enter a scalar value for the outside air temperature. If the temperature is equal to or above 80.0F, send a message to the command window telling the user to wear shorts. If the temperature is between 60.0F and 80.0F, send a message to the command window telling the user that it’s a beautiful day. If the temperature is equal to or below 60.0F, send a message to the command window telling the user to wear a jacket or a coat.
2.) Use a for loop to sum the elements in the following vector:
x = [1, 23, 43, 72, 87, 56, 98, 33]
3.) Repeat the previous problem, this time using a while loop

답변 (1개)

Image Analyst
Image Analyst 2016년 11월 2일
See this snippet. Adapt as needed:
% Ask user for two floating point numbers.
defaultValue = {'45.67', '78.91'};
titleBar = 'Enter a value';
userPrompt = {'Enter floating point number 1 : ', 'Enter floating point number 2: '};
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})
usersValue2 = 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.
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
% Do the same for usersValue2
theSum = 0;
for k = 1 : length(x)
theSum = ....... x(k) .....you finish
end
index = 1
while index < length(x)
theSum = .... % Add in the value of x for that index
index = .... % Increment the index
end

카테고리

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