Using vectors

10 vues (au cours des 30 derniers jours)
Kevin
Kevin le 11 Fév 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

Réponse acceptée

Image Analyst
Image Analyst le 11 Fév 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

Plus de réponses (0)

Catégories

En savoir plus sur Resizing and Reshaping Matrices dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by