How do I make a matrix with a repeating pattern but with different values
Mostrar comentarios más antiguos
I have two variables xi and yi both with size nx1 and I want to create the following matrix:
M= [x1 0 y1; y1 0 x1; x2 0 y2; y2 0 x2; ... ;yn 0 xn].
I've tried using repmat but that just repeats the first row over and over.
Respuestas (1)
David Hill
el 18 de Oct. de 2022
Editada: David Hill
el 18 de Oct. de 2022
x=randi(100,5,1)
y=randi(100,5,1)
z=zeros(size(x));
M=[x';z';y';y';z';x']
M=reshape(M(:),3,[])'
Categorías
Más información sobre Creating and Concatenating Matrices en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!