Using vectors

12 views (last 30 days)
Kevin
Kevin on 11 Feb 2012
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

Accepted Answer

Image Analyst
Image Analyst on 11 Feb 2012
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

More Answers (0)

Categories

Find more on Resizing and Reshaping Matrices 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!