How to create a 3D matrix from subtracting 2D matrices (like creating 2D matrix from subtracting vectors)?

2 次查看(过去 30 天)
Hi,
I wish to extend the behavior of subtracting a row vector and a column vector to matrices. Let me provide an example: Suppose A and B are two n x n matrices. I want to obtain matrix C such that C(:,:,i) = A(:,i)-B(i,:), i runs from 1 to n.
Is there a way to do this without for-loops?
Thanks,
Mohit.

采纳的回答

Stephen23
Stephen23 2022-1-19
C = permute(A,[1,3,2]) - permute(B,[3,2,1])

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Filter Analysis 的更多信息

产品


版本

R2020b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by