Effacer les filtres
Effacer les filtres

When given a matrix with x columns, how do you multiply the first column by 1, the second column by 2, etc?

2 vues (au cours des 30 derniers jours)
For example, if the matrix has 4 columns. I want to multiply the first column by 1, the second column by 2, the third column by 3 and the fourth column by 4. How can I create a function for this?

Réponse acceptée

the cyclist
the cyclist le 4 Oct 2014
Modifié(e) : the cyclist le 4 Oct 2014
Use bsxfun(). For example,
A = rand(3,4);
B = bsxfun(@times,A,1:4)
More generally,
B = bsxfun(@times,A,1:size(A,2))

Plus de réponses (0)

Catégories

En savoir plus sur Operators and Elementary Operations 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