How can I subtract a 2-d array from every slice of a 3-d array?
16 次查看(过去 30 天)
显示 更早的评论
A is a 512 x 512 x 200 array representing a stack of 200 monochrome images of resolution 512x512.
d = size(A)
d =
512 512 200
C is an 'offset' image that I want to deduct from each image in A. C has dimensions 512 x 512.
A(:,:,1) = A(:,:,1) - C;
A(:,:,2) = A(:,:,2) - C;
A(:,:,3) = A(:,:,3) - C;
A(:,:,4) = A(:,:,4) - C;
% and so on
I know that I could do a 'for' loop to handle this. Is there a better 'one-line' solution?
0 个评论
采纳的回答
Walter Roberson
2022-7-18
A = randi(9, 5, 5, 3);
C = randi(9, 5, 5);
newA = A - C;
%demonstrate that it worked
A(:,:,1)
C
A(:,:,1) - C
newA(:,:,1)
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!