필터 지우기
필터 지우기

Creating a matrix which has particular order of element ?

조회 수: 1 (최근 30일)
P K
P K 2019년 1월 21일
편집: Andrei Bobrov 2019년 1월 21일
Hello all,
I have to obtain a matrix. The matrix looks like
A=[1 0 0 0 0 0;0 2 0 0 0 0;3 0 4 0 0 0;0 5 0 6 0 0;7 0 8 0 9 0;0 10 0 11 0 12];
% There is a sequence.Odd row and even row.
% ODD ROW- Element stasts from first column
% EVEN ROW- Element start from second coloumn
% Each element is +1 to the previous element.
I can do this with "FOR-LOOP". But is there some effiecient way to do this.
Thanks you !

채택된 답변

Andrei Bobrov
Andrei Bobrov 2019년 1월 21일
편집: Andrei Bobrov 2019년 1월 21일
m = 6;
n = 6;
lo = triu(~rem((1:n)' + (1:m),2));
out = int64(lo);
out(lo) = 1:nnz(lo);
out = out';
with kron
m = 7;
n = 6;
out = triu(kron(ones(ceil(n/2),ceil(m/2)),[1,0;0,1]));
out = out(1:n,1:m);
out(out~=0) = 1:nnz(out);
out = out';

추가 답변 (1개)

Kevin Phung
Kevin Phung 2019년 1월 21일
Can you be more clear in what you are trying to do? Is this pattern supposed to go on? Or is this matrix A that you have provided exactly what you need, and you are looking for a way to programmatically create it rather than typing it out .

카테고리

Help CenterFile Exchange에서 Mathematics and Optimization에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by