How to create a symetric matrix with a vector?

2 views (last 30 days)
Hello everyone,
I would like to know how I can create a symetric matrix only with a vector. Per example:
v=[1 2 3 4 5]
And the result that I would like to obtain:
A = [1 2 3 4 5; 2 2 3 4 5; 3 3 3 4 5; 4 4 4 4 5; 5 5 5 5 5]
I hope that it could be understand well.
I have been searching and I have found the Toeplitz matrix but it doesn't resolves my problem.
Thanks in advance

Accepted Answer

Stephen23
Stephen23 on 8 Feb 2021
Edited: Stephen23 on 8 Feb 2021
A general solution using indexing:
V = [1,2,3,4,5]
V = 1×5
1 2 3 4 5
X = 1:numel(V);
M = V(max(X,X.'))
M = 5×5
1 2 3 4 5 2 2 3 4 5 3 3 3 4 5 4 4 4 4 5 5 5 5 5 5

More Answers (0)

Products


Release

R2019b

Community Treasure Hunt

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

Start Hunting!