Subtracting a value in a 3D array with all values in another 3D array
조회 수: 4 (최근 30일)
이전 댓글 표시
Hello, I have 2 three-dimensional arrays, i would like to take the first value in the first array and subtract it with all values in the second array, and then the second value in the first array with all values in the second array, and in each time the smallest value of the subtraction is put in a new array.
Thank you in advance
댓글 수: 2
채택된 답변
Jan
2022년 11월 26일
편집: Jan
2022년 11월 26일
A = rand(5,6,7);
B = rand(6,7,8);
D = min(A(:).' - B(:), [], 1);
Result = reshape(D, size(A));
If the intermediate matrix A(:).'-B(:) exhausts the available RAM, use a loop:
Result = zeros(size(A));
for k = 1:numel(A)
Result(k) = min(A(k) - B, [], 'all');
end
댓글 수: 2
Jan
2022년 11월 27일
[D, Pos] = min(A(:).' - B(:), [], 1);
determines the position also as linear index. But what do you exactly need as output "position" for 3D arrays?
I do not understand, what this means: "if the smallest value is in position 4 then the value in the results matrix is the difference, and the array is 6." Why 6?
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Matrices and Arrays에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!