How do I make a matrix with a repeating pattern but with different values
이전 댓글 표시
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.
답변 (1개)
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,[])'
카테고리
도움말 센터 및 File Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!