Dividing two non-zero arrays gives me an array of zeros
7 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hi, I'm dividing two arrays of equal size by eachother. These arrays do have 0's in them but not all the values are zero.
When I Divide the two I get an array of equal size to them both but all elements in the array are zero.
Here is an example
if true
x = ones(100)
y = ones(100)
z = x./y
z
% code
end
except when I return my 'z' I get an array of zeroes. Does anyone have any idea why this is and what a fix might be?
My x is a 100x100 double and my y is 100x100 double
Any help appreciated as always
2 commentaires
jgg
le 12 Fév 2016
Does that code in your example generate all zeroes for you? It doesn't on my system (Windows 10 x64, R2015a)?
Réponses (1)
Walter Roberson
le 12 Fév 2016
Your actual arrays are one of the integer data classes, such as if you are trying to divide one uint8 image by another . You need to double() the arrays before doing the division.
2 commentaires
Walter Roberson
le 12 Fév 2016
Modifié(e) : Walter Roberson
le 12 Fév 2016
Looks plausible.
new_b = b_c ./ double(rMagPriCubed(:,:,[1 1 1]));
and now you could select layers from new_b if you wanted.
Voir également
Catégories
En savoir plus sur Matrix Indexing dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!