How to make a program to consider, even the decimal values of the calculated data?
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
kintali narendra
am 7 Feb. 2017
Kommentiert: kintali narendra
am 7 Feb. 2017
In the program I need to find inverse of a number, but when I find inverse it is rounding it to ZERO. I tried "double" and "format long" it is not working, Please help me. The values are the centroid of a image in pixcels.
example : 1/ 131 = 0.0076
I want to use 0.0076 but the value stored in the variable is 0. I tried "double(1/131)" still it gives 0, I even gave the command "format long" before calculating, still there is no use, What I need to do?
HERE IS THE CODE
L = (centroidRed(1) - 320);
M = (320 - centroidRed2(1));
format long
lm = L+M
Distance = B*320/(tand(29)*(lm));
Distance_inches = Distance* 0.0393701;
LM(end+1) = double(1/(lm)) % accumulating the L+M to a matrix
0 Kommentare
Akzeptierte Antwort
Walter Roberson
am 7 Feb. 2017
L = (double(centroidRed(1)) - 320);
M = (320 - double(centroidRed2(1)));
lm = L+M
LM(end+1) = 1 ./ lm;
This requires, though, that LM not have been initialized to one of the integer data types, and the double() that it uses assume that centroidRed is for some reason one of the integer data types (not common for centroids, but could happen.)
The problem is potentially just that LM has been initialized to one of the integer data types and that centroidRed* are double after all. If that is the case then just make sure you initialize LM as double, and then you could use
L = centroidRed(1) - 320;
M = 320 - centroidRed2(1));
lm = L+M
LM(end+1) = 1 ./ lm;
Weitere Antworten (0)
Siehe auch
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!