How can I subtract a 2-d array from every slice of a 3-d array?
15 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Steve Francis
am 18 Jul. 2022
Kommentiert: Steve Francis
am 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 Kommentare
Akzeptierte Antwort
Walter Roberson
am 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)
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Logical finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!