필터 지우기
필터 지우기

how to create rectangular checkerbox matrix

조회 수: 1 (최근 30일)
xplore29
xplore29 2013년 7월 28일
I need to create M as follows
M=[1 0 1 0;0 1 0 1;1 0 1 0 ]
where m=size(M,1);n=size(M,2)
My code should take m,n as input and its output should be M
Code 1: p=m+1; q=n+1 A=repmat(eye(2),p,q) M=A(1:m,1:n)
Code 2: colvector=[1 0 1 ] rowvector=[1 0 1 0] M=hankel(colvector,rowvector)
The problem with Code2 is that I don't know how to create colvector and rowvector in the first place
I have read the following thread and it talks about generating square matrices of such nature but I dont want to restrict M to be a square matrix

채택된 답변

Azzi Abdelmalek
Azzi Abdelmalek 2013년 7월 28일
n=7;
m=5;
colvector=ones(1,m);
colvector(2:2:end)=0;
rowvector=ones(1,n);
rowvector(2:2:end)=0;
M=hankel(colvector,rowvector)

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Multidimensional Arrays에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by