How to convert temperature with multiple "if" statements?
4 次查看(过去 30 天)
显示 更早的评论
I am trying to set create a function that will convert a temperature from unit to another. But unitFrom and unitTo must be part of the function. In other words, I am providing the temperature, the unitFrom and the unitTo. The units are Celsius, Fahrenheit and Kelvin. I have multiple if statements because converting Celsius could go two ways, to Fahrenheit or to Kelvin. How do I do this in MatLab? Please see attached photo of what I have so far. I am testing my function by writing this into the command and currently I get an error: convertTemperature(50,
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/151031/image.png)
’Fahrenheit’,’Celsius’)
0 个评论
回答(1 个)
Star Strider
2015-6-9
The double equal (==) doesn’t work with strings. Use the strcmp or strcmpi functions instead.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Data Type Conversion 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!