Borrar filtros
Borrar filtros

Split 2 lines of a matrix?

2 visualizaciones (últimos 30 días)
Emanuel
Emanuel el 1 de Jun. de 2019
Comentada: dpb el 6 de Jun. de 2019
I have this 4x4 matrix.
I want to get lines 3 and 4 to put them up on the matrix, like:
0 1 1 1 1 1 1 1
1 1 1 1 to 0 1 1 1
1 1 1 1
I've made a 2x4 example to make things easier.
Thanks

Respuesta aceptada

dpb
dpb el 1 de Jun. de 2019
B=[A(3:4,:);A]; % create new array keeping old
A=[A(3:4,:);A]; % new array replaces/augments old
More generically,
N=2; % number rows at end to add to beginning
A=[A(end-N+1:end,:);A]; % add N last lines at beginning
  2 comentarios
Emanuel
Emanuel el 6 de Jun. de 2019
sorry if i'm asking too much, but could you explain the logic behind
A=[A(end-N+1:end,:);A]; % add N last lines at beginning
?
dpb
dpb el 6 de Jun. de 2019
Just a simple substitution of variables from the explicit case--with the generic ML function end for the last row and the expression for the row number from the end to pick up N rows.
For your specific case that picked up two rows and has size(A,1)==>4, plug in the values and see what you get...

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Multidimensional Arrays 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