Matrix dimensions must agree error

1 次查看(过去 30 天)
This is my code.
Temp_Coke = input('What is the current temperature of the Coke (deg F)? ', 's');
Temp_Fridge = input("What is the temperature of your friend's fridge (deg F)? ", 's');
Ideal_Coke_Temp = input('What is the ideal Coke drinking temperature (deg F)? ', 's');
k = 0.058;
t = log((Ideal_Coke_Temp-Temp_Fridge)/(Temp_Coke-Temp_Fridge))*(-1./k);
fprintf('It should take %d minutes to cool the Coke to %d degrees F from %d degrees F if my fridge has a temperature of %d degrees F.',t,Ideal_Coke_Temp,Temp_Coke,Temp_Fridge);
It's a simple code to find t(Time) from newtons law of cooling. However, when I run the code, the t = equation comes up as matrix dimensions must agree error and i dont know how to fix it.

采纳的回答

Stephen23
Stephen23 2020-9-11
Wrap each input with str2double, e.g.:
Temp_Coke = str2double(input('What is the current temperature of the Coke (deg F)? ', 's'));
  1 个评论
Brendan Proaps
Brendan Proaps 2020-9-11
how do i get it to not give me an e number, like 43 minutes instead of 4.31124e1

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Creating and Concatenating Matrices 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by