Borrar filtros
Borrar filtros

Help with rowshift needed

1 visualización (últimos 30 días)
Tom
Tom el 13 de Nov. de 2013
I have narrowed down the problem from my previous question.
I have a for loop
for ashift = 1:n
x = [x(:,1) - x(ashift,1) x(:,2) - x(ashift,2) ...
x(:,3) - x(ashift,3)]
end
which outputs four matrices (when n = 4) like so:
x =
0 0 0
-21.3131 8.6558 -2.5770
-21.3446 15.1527 -11.0297
-14.4331 16.9392 9.8923
x =
21.3131 -8.6558 2.5770
0 0 0
-0.0315 6.4970 -8.4527
6.8800 8.2834 12.4693
x =
21.3446 -15.1527 11.0297
0.0315 -6.4970 8.4527
0 0 0
6.9115 1.7865 20.9220
x =
14.4331 -16.9392 -9.8923
-6.8800 -8.2834 -12.4693
-6.9115 -1.7865 -20.9220
0 0 0
But I need the rows with zeros in to be at the top of the matrix to simplify subsequent calculations, so I am implementing:
rowshift = 0;
for ashift = 1:n
x = [x(:,1) - x(ashift,1) x(:,2) - x(ashift,2) ...
x(:,3) - x(ashift,3)];
x = circshift(x,rowshift)
rowshift = rowshift - 1;
end
However for some reason this changes the order of the output, i.e:
x =
0 0 0
-21.3131 8.6558 -2.5770
-21.3446 15.1527 -11.0297
-14.4331 16.9392 9.8923
x =
0 0 0
-0.0315 6.4970 -8.4527
6.8800 8.2834 12.4693
21.3131 -8.6558 2.5770
x =
0 0 0
14.4331 -16.9392 -9.8923
-6.8800 -8.2834 -12.4693
-6.9115 -1.7865 -20.9220
x =
0 0 0
6.9115 1.7865 20.9220
21.3446 -15.1527 11.0297
0.0315 -6.4970 8.4527
You see the 3rd and 4th matrices are changing order. Can anyone explain why this is happening, and how to stop it from happening?
Kind regards,
Tom

Respuestas (0)

Categorías

Más información sobre Resizing and Reshaping Matrices en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by