How can I subtract a 2-d array from every slice of a 3-d array?
15 views (last 30 days)
Show older comments
Steve Francis
on 18 Jul 2022
Commented: Steve Francis
on 18 Jul 2022
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 Comments
Accepted Answer
Walter Roberson
on 18 Jul 2022
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)
More Answers (0)
See Also
Categories
Find more on Logical in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!