Effacer les filtres
Effacer les filtres

How to find the product of each element of a matrix by itself and by the other elemets at the same row?

1 vue (au cours des 30 derniers jours)
input:
x = [a,b,c;
d,e,f]
output:
y = [a^2,a*b,a*c,b^2,b*c,c^2;
d^2,d*e,d*f,e^2,e*f,f^2]

Réponse acceptée

Andrei Bobrov
Andrei Bobrov le 27 Mar 2015
Modifié(e) : Andrei Bobrov le 31 Mar 2015
EDIT
[n1,n2] = ndgrid(1:size(x));
y = x(:,nonzeros(tril(n1))).*x(:,nonzeros(tril(n2)));
  3 commentaires
Matt Talebi
Matt Talebi le 29 Mar 2015
Hi Andrei! Sorry it seems that I should have mentioned the dimension of my actual matrix, which is 85 * 15. I'm given this error: "Error using .* Matrix dimensions must agree." I appreciate your help again!

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