how to do convolution of two arrays in 3d?
조회 수: 8 (최근 30일)
이전 댓글 표시
hi everyone
i am trying to do convolution between a 371x391x23 and 371x391x23 array. however when i used convn, the output which i got had only Nan values in it. one of the input array has some Nan values in it. is it because of that the output also became Nan? kindly help me to solve it.
댓글 수: 0
답변 (2개)
Walter Roberson
2021년 12월 27일
Yes, a single nan can pollute more than 95% of the output of a matrix with those dimensions, if it happens to be at the center of the array.
There is pretty much no point is doing a convolution with nan values present
댓글 수: 2
Walter Roberson
2021년 12월 27일
No. If you look at the formula at https://www.mathworks.com/help/matlab/ref/convn.html#bvg3kvh-9 then note that every A value is involved in the computation so if one of them is nan then at least one individual multiplication gives a nan result. But there is the summation over all of the values, and so nan is certain to be involved somewhere in the summation, so you are going to get nan as the result for all locations (except perhaps at some border locations.)
Matt J
2021년 12월 27일
편집: Matt J
2021년 12월 28일
Consider overwriting the NaNs with zeros
A(isnan(A))=0;
or more sophisticated missing data inpainting routines offered on the file exchange, e.g.,
댓글 수: 2
Walter Roberson
2021년 12월 28일
Note that putting in any finite numeric value is going to change the entire meaning of the convolution.
A = magic(8)
B = A.'
C1 = conv2(A, B, 'same')
A(4,4) = nan;
C2 = conv2(A, B, 'same')
A(4,4) = 0;
C3 = conv2(A, B, 'same')
A(4,4) = 1;
C4 = conv2(A, B, 'same')
sum(C4-C3, 'all')
sum(A, 'all'), sum(B, 'all')
... I can't see any obvious simple relationship
참고 항목
카테고리
Help Center 및 File Exchange에서 Logical에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!