how to divide matrix in columns and pair them?

1 vue (au cours des 30 derniers jours)
Mudasir Ahmed
Mudasir Ahmed le 8 Août 2015
Commenté : Mudasir Ahmed le 8 Août 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

Réponse acceptée

Walter Roberson
Walter Roberson le 8 Août 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 commentaires
Walter Roberson
Walter Roberson le 8 Août 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 le 8 Août 2015
Thanks allot sir :)

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Matrix Indexing dans Help Center et File Exchange

Tags

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by