How to perform this matrix manupulation.?

조회 수: 1 (최근 30일)
harshal j
harshal j 2016년 4월 6일
댓글: harshal j 2016년 4월 6일
Hi, I have a row matrix which contains 20 elements ranging from 1 to 20 eg [1,2,3,4...19,20] now i want to arrange the matrix like this [18,19,20,1,2,3,4] in first row in second row [19,20,1,2,3,4,5] in thrid row [20,1,2,3,4,5,6] and so on..means i want to consider 3 elements before the 1 and three elements after the 1 for the first row and same process i have to follow for all the elements...my final matrix will of size 7x20, i want to write this algorithm in MATLAB, Please help me to write this logic. thanks in advance

채택된 답변

Andrei Bobrov
Andrei Bobrov 2016년 4월 6일
편집: Andrei Bobrov 2016년 4월 6일
z = circshift(1:20,[0 3]');
out = hankel(z,rem((z(end):z(end)+6)-1,20)+1);
  댓글 수: 1
harshal j
harshal j 2016년 4월 6일
thank u so much for the answer ..!!

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Stalin Samuel
Stalin Samuel 2016년 4월 6일
a = 1:20;
n = 7;
A = zeros(n,length(a));
n1 = 3
for it =1:n
A(it,:)= circshift(a',n1)
n1=n1-1;
end

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by