How can I subtract a 2-d array from every slice of a 3-d array?
15 ビュー (過去 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 件)
参考
カテゴリ
Help Center および File Exchange で Logical についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!