Effacer les filtres
Effacer les filtres

matrix columnwise subtraction

1 vue (au cours des 30 derniers jours)
zozo
zozo le 25 Nov 2011
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?

Réponse acceptée

Image Analyst
Image Analyst le 25 Nov 2011
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 commentaires
Titus Edelhofer
Titus Edelhofer le 25 Nov 2011
Small typo, to reproduce the example you need to subtract m from m1: m1MinusM = bsxfun(@minus, m1, m).
zozo
zozo le 26 Nov 2011
thank you!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Logical dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by