Transforming vector into triangular matrix

21 vues (au cours des 30 derniers jours)
Jeff
Jeff le 2 Fév 2014
Commenté : Jeff le 2 Fév 2014
Hi guys,
I've got a 48x1 vector say [x1; x2; x3; x4;...x48]
I want to transform this into a 48x48 matrix that looks like:
x1 0 0 0 ...
x1 x2 0 0 ...
x1 x2 x3 0 ...
x1 x2 x3 x4 ...
....
What are some of the ways to do this? I know I could use diag() but that would only get me 1 diagonal line. Or should I try and use tril()? Thanks!

Réponse acceptée

Amit
Amit le 2 Fév 2014
Lets call it A Then
A_new = repmat(A,1,48);
A_new = tril(A);
  1 commentaire
Jeff
Jeff le 2 Fév 2014
Perfect, thank you!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Creating and Concatenating Matrices 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