Info

Cette question est clôturée. Rouvrir pour modifier ou répondre.

Multiply each number in a matrix by the diagonal number of a given row using a for loop

1 vue (au cours des 30 derniers jours)
Vinny
Vinny le 24 Avr 2016
Clôturé : MATLAB Answer Bot le 20 Août 2021
I have this matrix here
a=[2 -5 7;1 1 3;4 5 12];
I need to multiply each of the numbers in the row by the diagonal of that row using a for loop. So afterwards it should look like this
a=[4 -10 14;1 1 3;48 60 144]
I have no idea on how to do this, so any help on how to do this is appreciated, thank you.

Réponses (1)

Azzi Abdelmalek
Azzi Abdelmalek le 24 Avr 2016
Modifié(e) : Azzi Abdelmalek le 24 Avr 2016
a=[2 -5 7;1 1 3;4 5 12];
b=bsxfun(@times,a,diag(a))

Cette question est clôturée.

Community Treasure Hunt

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

Start Hunting!

Translated by