Cut differently odd and even rows in matrix
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Sergey Makovkin
el 21 de Nov. de 2016
Editada: Alexandra Harkai
el 21 de Nov. de 2016
Hi, all!
I have a matrix like that:
a = [ 1 2 3 4 5 6 7 8;
9 10 11 12 13 14 15 16;
17 18 19 20 21 22 23 24;
25 26 27 28 29 30 31 32];
I need to get this matrix:
[ 3 4 5 6 7 8;
9 10 11 12 13 14;
19 20 21 22 23 24;
25 26 27 28 29 30];
I want to cut first two values in odd lines and cut last two values in even lines. I means that I need something like this:
a = a(3:8, 1:2:end) && a(1:6, 2:2:end)
But it is incorrect. How can I do it correctly?
0 comentarios
Respuesta aceptada
Alexandra Harkai
el 21 de Nov. de 2016
Editada: Alexandra Harkai
el 21 de Nov. de 2016
n = size(a, 2); % number of columns
a(1:2:n,:) = a(1:2:n,[[3:n],[1:2]]); % move first 2 elements in odd rows to the end
a = a(:, 1:n-2); % get rid of last 2 columns
Of course prettier to use circshift:
n = size(a, 2); % number of columns
a(1:2:n,:) = circshift(a(1:2:n,:),-2,2); % move first 2 elements in odd rows to the end
a = a(:, 1:n-2); % get rid of last 2 columns
0 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Logical en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!