how to divide matrix in columns and pair them?

조회 수: 1 (최근 30일)
Mudasir Ahmed
Mudasir Ahmed 2015년 8월 8일
댓글: Mudasir Ahmed 2015년 8월 8일
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

채택된 답변

Walter Roberson
Walter Roberson 2015년 8월 8일
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
Walter Roberson
Walter Roberson 2015년 8월 8일
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 2015년 8월 8일
Thanks allot sir :)

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by