Create a matrix with one vector

1 view (last 30 days)
Johannes Reiers
Johannes Reiers on 12 Jun 2022
Commented: Voss on 12 Jun 2022
Hey,
I want to create a matrix out of one vector.
v=[1,2,3,4]
And the matrix should have the form
M= 1 2 3 4
2 2 3 4
3 3 3 4
4 4 4 4
Is there an easy solution for that?
Thanks

Accepted Answer

Voss
Voss on 12 Jun 2022
v=[1,2,3,4];
N = numel(v);
idx = max(1:N,(1:N).');
M = v(idx)
M = 4×4
1 2 3 4 2 2 3 4 3 3 3 4 4 4 4 4

More Answers (1)

Jan
Jan on 12 Jun 2022
v = [1,2,3,4];
max(v, v.')
ans = 4×4
1 2 3 4 2 2 3 4 3 3 3 4 4 4 4 4

Categories

Find more on Matrices and Arrays in Help Center and File Exchange

Products


Release

R2022a

Community Treasure Hunt

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

Start Hunting!