Create a matrix with one vector

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

 Respuesta aceptada

Voss
Voss el 12 de Jun. de 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

2 comentarios

Johannes Reiers
Johannes Reiers el 12 de Jun. de 2022
Thanks a lot
Voss
Voss el 12 de Jun. de 2022
You're welcome!

Iniciar sesión para comentar.

Más respuestas (1)

Jan
Jan el 12 de Jun. de 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

Categorías

Más información sobre Elementary Math en Centro de ayuda y File Exchange.

Productos

Versión

R2022a

Etiquetas

Preguntada:

el 12 de Jun. de 2022

Comentada:

el 12 de Jun. de 2022

Community Treasure Hunt

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

Start Hunting!

Translated by