Simple Unit Conversion, Undefined variable Error
显示 更早的评论
I'm trying to write a function that should convert inch, feet, mm and cm to meters. Code is below;
function MetricWorks
x= input('Enter the Input Distance: ');
y= input('Enter the input Units(cm,mm,in,ft): ');
in=x*0.0254;
ft=x*0.3048;
cm=x*0.01;
mm=x*0.001;
switch y
case 'in'
fprintf('%0.1f inches is equal to %0.4f m \n',x,in)
case 'feet'
fprintf('%0.1f feet is equal to %0.4f m \n',x,ft)
case 'cm'
fprintf('%0.1f cm is equal to %0.4f m \n',x,cm)
case 'mm'
fprintf('%0.1f mm is equal to %0.4f m \n',x,mm)
endswitch
end
As you can guess it gives 'Undefined function or variable 'in'.' error. I don't know if there are any other possible errors after that.
Thanks in advance.
采纳的回答
更多回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Data Type Conversion 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!