MATLAB: Using vectors

programming

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

Best Answer

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