Azzera filtri
Azzera filtri

Conversion of feet.inch to meter

17 visualizzazioni (ultimi 30 giorni)
Sudhir Kumar
Sudhir Kumar il 5 Nov 2021
Modificato: Stephen23 il 5 Nov 2021
How to convert a number with 5'.9''(5 feet 9 inch) to meter. I have tried convlength() but here the problem is after decimal it taking the number as unit "feet" not in "inch".
Actullay I have a data vector X = [6.5 5.9 5.9 3.4] where left side of the decimal are in unit "feet" and right side of the decimal are in "inch"
I have tried to create own function which is like this but this is not efficient way as I have to put a comma(,) in bettween two number. Can someone help me out.
function x = conv_feet(feet,inch)
inch1 = feet*12;
ans_2 = (inch+inch1)*0.0254; % to convert inch scale into meter scale
x = ans_2;
end
  4 Commenti
Sudhir Kumar
Sudhir Kumar il 5 Nov 2021
I have redisgned my code as follows and i got the answer
function y = conv_feet(x)
feet_1= floor(x);
inch = x - feet_1;
inch = inch*10;
feet_2 = inch/12;
ans_2 = (feet_1 + feet_2)*0.3048;
y = ans_2
end
Stephen23
Stephen23 il 5 Nov 2021
Modificato: Stephen23 il 5 Nov 2021
"I have redisgned my code as follows and i got the answer"
I doubt that, because so far you have inconsistent handling of inches. Compare:
x = [5.01,5.09,5.9,5.11]
x = 1×4
5.0100 5.0900 5.9000 5.1100
feet_1= floor(x);
inch = x - feet_1;
inch = inch*10
inch = 1×4
0.1000 0.9000 9.0000 1.1000
Your very poor data design is causing you problems, which your code does not handle.

Accedi per commentare.

Risposta accettata

Stephen23
Stephen23 il 5 Nov 2021
Modificato: Stephen23 il 5 Nov 2021
Rather than abusing the definition of decimal numbers, a much better way to store feet and inches is in a matrix:
FI = [6,5;5,9;5,11;3,4] % [feet,inches]
FI = 4×2
6 5 5 9 5 11 3 4
Then your task is trivial using a very basic matrix mulitplication:
M = FI*[12;1]*0.0254 % meter per inch
M = 4×1
1.9558 1.7526 1.8034 1.0160
Better data design -> better code.

Più risposte (0)

Categorie

Scopri di più su Mathematics in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by