Undefined function 'times' for input arguments of type 'cell'.

3 次查看(过去 30 天)
I am trying to write a function that will determine the heat needed to change the temperature of water between two given temperatures and I keep getting this error. Anybody know how to fix it?
c_ice = 2060;
c_water = 4180;
c_steam = 2020;
Hf = 332000;
Hv = 2260000;
% Input
mass = inputdlg('What is the mass of the H2O?','Mass of H20');
statei = listdlg('PromptString', 'What is the initial state of the H2O?',...
'SelectionMode','Single',...
'ListString',{'Ice','Liquid','Gas'},...
'Name', 'Initial State',...
'ListSize',[230 100]);
statef = listdlg('PromptString', 'What is the final state of the H2O?',...
'SelectionMode','Single',...
'ListString',{'Ice','Liquid','Gas'},...
'Name', 'Final State',...
'ListSize',[230 100]);
switch statei
case 1
tempi = inputdlg('What is the initial temperature of the H2O between -273-0ºC',...
'Initial Temperature');
case 2
tempi = inputdlg('What is the initial temperature of the H2O between 0-100ºC',...
'Initial Temperature');
case 3
tempi = inputdlg('What is the initial temperature of the H2O between 100-300ºC',...
'Initial Temperature');
end
tempi = str2double(tempi);
switch statef
case 1
tempf = inputdlg('What is the final temperature of the H2O between -273-0ºC',...
'Final Temperature');
case 2
tempf = inputdlg('What is the final temperature of the H2O between 0-100ºC',...
'Final Temperature');
case 3
tempf = inputdlg('What is the final temperature of the H2O between 100-300ºC',...
'Final Temperature');
end
tempf = str2double(tempf);
% Process
if tempi < 0
if tempf < 0
heat = mass*c_ice*(tempf - tempi);
elseif tempf < 100
heat = mass*c_ice*(tempi) + mass*Hf + mass*c_water*(tempf);
else tempf > 100
heat = mass*c_ice*(tempi) + mass*Hf + mass*c_water*(100) + mass*Hv + mass*c_steam*(tempf - 100);
end
elseif tempi > 0 && tempi < 100
if tempf < 0
heat = mass*c_water*(-tempi) + mass*Hf + mass*c_ice*(-tempf);
elseif tempf < 100
heat = mass*c_water*(tempf - tempi);
else tempf > 100
heat = mass*c_water*(100 - tempi) + mass*Hv + mass*c_steam*(tempf - 100);
end
else
if tempf < 0
heat = mass*c_steam*(tempi - 100) + mass*Hv + mass*c_water*(100) + mass*Hf + mass*c_ice*(-tempf);
elseif tempf < 100
heat = mass*c_steam*(tempi - 100) + mass*Hv + mass*c_water*(tempf - 100);
else tempf > 100
heat = mass*c_ice*(tempf - tempi);
end
endc_ice = 2060;
c_water = 4180;
c_steam = 2020;
Hf = 332000;
Hv = 2260000;
% Input
mass = inputdlg('What is the mass of the H2O?','Mass of H20');
statei = listdlg('PromptString', 'What is the initial state of the H2O?',...
'SelectionMode','Single',...
'ListString',{'Ice','Liquid','Gas'},...
'Name', 'Initial State',...
'ListSize',[230 100]);
statef = listdlg('PromptString', 'What is the final state of the H2O?',...
'SelectionMode','Single',...
'ListString',{'Ice','Liquid','Gas'},...
'Name', 'Final State',...
'ListSize',[230 100]);
switch statei
case 1
tempi = inputdlg('What is the initial temperature of the H2O between -273-0ºC',...
'Initial Temperature');
case 2
tempi = inputdlg('What is the initial temperature of the H2O between 0-100ºC',...
'Initial Temperature');
case 3
tempi = inputdlg('What is the initial temperature of the H2O between 100-300ºC',...
'Initial Temperature');
end
tempi = str2double(tempi);
switch statef
case 1
tempf = inputdlg('What is the final temperature of the H2O between -273-0ºC',...
'Final Temperature');
case 2
tempf = inputdlg('What is the final temperature of the H2O between 0-100ºC',...
'Final Temperature');
case 3
tempf = inputdlg('What is the final temperature of the H2O between 100-300ºC',...
'Final Temperature');
end
tempf = str2double(tempf);
% Process
if tempi < 0
if tempf < 0
heat = mass*c_ice*(tempf - tempi);
elseif tempf < 100
heat = mass*c_ice*(tempi) + mass*Hf + mass*c_water*(tempf);
else tempf > 100
heat = mass*c_ice*(tempi) + mass*Hf + mass*c_water*(100) + mass*Hv + mass*c_steam*(tempf - 100);
end
elseif tempi > 0 && tempi < 100
if tempf < 0
heat = mass*c_water*(-tempi) + mass*Hf + mass*c_ice*(-tempf);
elseif tempf < 100
heat = mass*c_water*(tempf - tempi);
else tempf > 100
heat = mass*c_water*(100 - tempi) + mass*Hv + mass*c_steam*(tempf - 100);
end
else
if tempf < 0
heat = mass*c_steam*(tempi - 100) + mass*Hv + mass*c_water*(100) + mass*Hf + mass*c_ice*(-tempf);
elseif tempf < 100
heat = mass*c_steam*(tempi - 100) + mass*Hv + mass*c_water*(tempf - 100);
else tempf > 100
heat = mass*c_ice*(tempf - tempi);
end
end

采纳的回答

Teja Muppirala
Teja Muppirala 2012-12-17
When you use INPUTDLG to get input from the user, the result is stored as a string (text) in what is known as a cell array. It is not a numeric datatype, but rather a datatype that is often used to store mixed numbers/text, so you can't do numeric operations with it. You need to convert from a cell array/text to a plain old numeric array. You can use STR2DOUBLE to do this.
For example, you wrote this:
mass = inputdlg('What is the mass of the H2O?','Mass of H20')
Now "mass" is a cell array. To use it for further calculations, change it to a double:
mass = str2double(mass)
Now you can do things like
mass * 10
mass + 1
You will need to do this for all the numbers that you input using INPUTDLG.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Data Type Identification 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by