필터 지우기
필터 지우기

matrix columnwise subtraction

조회 수: 1 (최근 30일)
zozo
zozo 2011년 11월 25일
I have the following matrix:
[ 1 2 3
1 3 4
4 5 6]
I need:
[ 0 -1 -2
0 -2 -3
0 -1 -2]
How can I do it?

채택된 답변

Image Analyst
Image Analyst 2011년 11월 25일
Try bsxfun:
% Generate sample data.
m = rand(3,5)
% Extract out the first column
m1 = m(:,1)
% Subtract first column from all the columns.
mMinusM1 = bsxfun(@minus,m,m1)
  댓글 수: 2
Titus Edelhofer
Titus Edelhofer 2011년 11월 25일
Small typo, to reproduce the example you need to subtract m from m1: m1MinusM = bsxfun(@minus, m1, m).
zozo
zozo 2011년 11월 26일
thank you!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by