필터 지우기
필터 지우기

Replacing alternate columns of matrix with another matrix

조회 수: 3 (최근 30일)
shanmukh
shanmukh 2013년 8월 7일
I have a matrix A and B, i need to replace alternate rows of B with A to form C
A={
1
2
3
}
B= {
4 7 10
5 8 11
6 9 12
}
C= {
1 4 1 7 1 10
2 5 2 8 2 11
3 6 3 9 3 12
}
Please let me know how to do this

채택된 답변

the cyclist
the cyclist 2013년 8월 7일
Here is one way:
[m,n] = size(B);
C = zeros(m,2*n);
C(:,1:2:end) = repmat(A,[1,n]);
C(:,2:2:end) = B;

추가 답변 (1개)

David Sanchez
David Sanchez 2013년 8월 7일
A= [1;2;3];
B = [4 7 10;
5 8 11;
6 9 12];
C = zeros(size(B,2),size(B,1)*2); % initialize C
for k=1:length(A)
C(:,2*k-1) = A;
C(:,2*k) = B(:,k);
end

카테고리

Help CenterFile Exchange에서 Multidimensional Arrays에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by