how to divide matrix in columns and pair them?

1 view (last 30 days)
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

Accepted Answer

Walter Roberson
Walter Roberson on 8 Aug 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 Comments
Walter Roberson
Walter Roberson on 8 Aug 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.

Sign in to comment.

More Answers (0)

Tags

Products

Community Treasure Hunt

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

Start Hunting!