How to perform this matrix manupulation.?
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
harshal j
am 6 Apr. 2016
Kommentiert: harshal j
am 6 Apr. 2016
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
0 Kommentare
Akzeptierte Antwort
Andrei Bobrov
am 6 Apr. 2016
Bearbeitet: Andrei Bobrov
am 6 Apr. 2016
z = circshift(1:20,[0 3]');
out = hankel(z,rem((z(end):z(end)+6)-1,20)+1);
Weitere Antworten (1)
Stalin Samuel
am 6 Apr. 2016
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
Siehe auch
Kategorien
Mehr zu Matrices and Arrays finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!