How do I make a matrix with a repeating pattern but with different values
Ältere Kommentare anzeigen
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.
Antworten (1)
David Hill
am 18 Okt. 2022
Bearbeitet: David Hill
am 18 Okt. 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,[])'
Kategorien
Mehr zu Creating and Concatenating Matrices finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!