Using vectors

조회 수: 12 (최근 30일)
Kevin
Kevin 2012년 2월 11일
Writing a program where user has to input a temperature along with the unit. I then put these into vectors and convert the Temperatures into F,C,K, and R. I'm having a little trouble with my if statements to determine whether the temperature inputted is C,F etc...
Temp = input('Enter the temperature:'); EoSI = input('Enter the units:','s');
I=I+1;
if EoSI = 'C';
TempC(I) = Temp;
TempK(I) = Temp + 273;
TempF(I) = Temp * (9/5) + 32;
TempR(I) = TempK(I);
Just need a little help to get me back on the right track, wasn't sure if I can set EoSI = C in a if statement

채택된 답변

Image Analyst
Image Analyst 2012년 2월 11일
Try this:
% Set up the dialog box parameters
prompt = {'Enter temperature:','Enter the temperature scale:'};
dialogTitle = 'Enter parameters';
numberOfLines = 1;
defaultAnswers = {'100','C'};
userResponse = inputdlg(prompt, dialogTitle, numberOfLines, defaultAnswers);
% Extract out individual variables from the user response.
temperature = str2double(userResponse{1})
EoSI = upper(userResponse{2})
TempC = zeros(100,1);
TempK = zeros(100,1);
TempR = zeros(100,1);
TempF = zeros(100,1);
I = 1; % Some index.
if strfind(EoSI, 'C') > 0
TempC(I) = temperature
elseif strfind(EoSI, 'K') > 0
TempK(I) = temperature + 273
elseif strfind(EoSI, 'F') > 0
TempF(I) = temperature * (9/5) + 32
elseif strfind(EoSI, 'R') > 0
TempR(I) = TempK(I)
end

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Resizing and Reshaping Matrices에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by