Using vectors
10 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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
0 commentaires
Réponse acceptée
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
0 commentaires
Plus de réponses (0)
Voir également
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!