Matrix column subtraction problem
이전 댓글 표시
I know this is really basic stuff but unfortunately I can't get to the right solution.
I have for example these 2 matrices:
matrixA=[1 5;5 2;0 0;3 2;3 6]
and
matrixB=[4 5 6;8 5 2;3 3 2;1 2 1;2 5 4]
What I want to do is to subtract all columns in matrixB from column 1 and column 2 respectively in matrixA. So I want to make
matrixC=[1-4 1-5 1-6 5-4 5-5 5-6;5-8 5-5 5-2 2-8 2-5 2-2;....;....;.....]
채택된 답변
추가 답변 (1개)
Walter Roberson
2018년 3월 11일
[matrixA(:,1)-matrixB,matrixA(:,2)-matrixB]
This might require R2016b or later.
댓글 수: 2
Jakub Nosek
2018년 3월 11일
Walter Roberson
2018년 3월 11일
cell2mat(arrayfun(@(COLIDX) bsxfun(@minus, matrixA(:,COLIDX), matrixB), 1:size(matrixA,2), 'uniform', 0))
카테고리
도움말 센터 및 File Exchange에서 Linear Equations에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!