Shift elements of matrix N times (MATLAB)

1 Ansicht (letzte 30 Tage)
high speed
high speed am 9 Mär. 2022
Kommentiert: David Hill am 9 Mär. 2022
I have a parameter m and an identity matrix of dimensions m-1*m-1
for example: m=4 so the identity matrix is 3*3
a1=[1 0 0
0 1 0
0 0 1]
I want to shift this matrix m-2 times, to obtain :
a2=[0 1 0
0 0 1
1 0 0]
h3=[0 0 1
1 0 0
0 1 0]
In this case I can use this program:
for i=1:m
a2=circshift(h1,[0 1]);
a3=circshift(h2,[0 1]);
How can I program that in a general way please (in case if m=100 for example) !

Akzeptierte Antwort

David Hill
David Hill am 9 Mär. 2022
  2 Kommentare
David Hill
David Hill am 9 Mär. 2022
I did not understand that you wanted to save all of the matrices. Below saves all the matrices into a single 3D matrix for any m.
for k=2:m-2

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)


Find more on Mathematics in Help Center and File Exchange


Community Treasure Hunt

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

Start Hunting!

Translated by