필터 지우기
필터 지우기

Dividing two non-zero arrays gives me an array of zeros

조회 수: 7 (최근 30일)
John Draper
John Draper 2016년 2월 12일
편집: Walter Roberson 2016년 2월 12일
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
jgg
jgg 2016년 2월 12일
Does that code in your example generate all zeroes for you? It doesn't on my system (Windows 10 x64, R2015a)?
John Draper
John Draper 2016년 2월 12일
편집: John Draper 2016년 2월 12일
Yes, for me it does.
whos z is a 100x100 double in my code

댓글을 달려면 로그인하십시오.

답변 (1개)

Walter Roberson
Walter Roberson 2016년 2월 12일
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
John Draper
John Draper 2016년 2월 12일
편집: Walter Roberson 2016년 2월 12일
Here is a section of my code, does this look correct?
ii = double(b_c(:,:,1))
jj = double(b_c(:,:,2))
kk = double(b_c(:,:,3))
rMPCdouble = double(rMagPriCubed)
b_ci = ii./rMPCdouble;
b_cj = jj./rMPCdouble;
b_ck = kk./rMPCdouble;
Walter Roberson
Walter Roberson 2016년 2월 12일
편집: Walter Roberson 2016년 2월 12일
Looks plausible.
new_b = b_c ./ double(rMagPriCubed(:,:,[1 1 1]));
and now you could select layers from new_b if you wanted.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Structures에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by