Borrar filtros
Borrar filtros

how to divide matrix in columns and pair them?

1 visualización (últimos 30 días)
Mudasir Ahmed
Mudasir Ahmed el 8 de Ag. de 2015
Comentada: Mudasir Ahmed el 8 de Ag. de 2015
hi i have the following matrix. i want to split this according to column and pair them [0,0; 5,10; 10,15; 85,90; 95,95]
result for first column:
[0,5;
5;10;
10,85;
85,95]
and result for second column
[0,10;
10;15;
15,90;
90,95]
kindly help me :)
regards

Respuesta aceptada

Walter Roberson
Walter Roberson el 8 de Ag. de 2015
A = [0,0; 5,10; 10,15; 85,90; 95,95];
pairs = cell(size(A,2),1);
for K = 1 : size(A,2)
pairs{K} = [A(1:end-1,K), A(2:end,K)];
end
  3 comentarios
Walter Roberson
Walter Roberson el 8 de Ag. de 2015
A = [0,0; 5,10; 10,15; 85,90; 95,95];
pairs = zeros(size(A,1)-1, 2, size(A,2));
for K = 1 : size(A,2)
pairs(:,:,K) = [A(1:end-1,K), A(2:end,K)];
end
Now pairs(:,:,K) corresponds to the K'th column of the original array.
Mudasir Ahmed
Mudasir Ahmed el 8 de Ag. de 2015
Thanks allot sir :)

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Matrix Indexing en Help Center y File Exchange.

Etiquetas

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by