필터 지우기
필터 지우기

Combining matrix of different dimension.

조회 수: 2 (최근 30일)
Gratitude Kim
Gratitude Kim 2017년 7월 26일
답변: Andrei Bobrov 2017년 7월 26일
I have three matrix. Matrix 1 = [2 2; 0 0],Matrix 2 =[1 1;0 0] and Matrix 3=[2 2 2 2 ;3 3 3 3] . I will like to combine these 3 matrix such that it becomes [2 2 0 0;0 0 0 0;1 1 0 0;0 0 0 0;2 2 2 2;3 3 3 3]. Appreciate your kind assistance. Thanks.

채택된 답변

Andrei Bobrov
Andrei Bobrov 2017년 7월 26일
m1 = [2 2; 0 0];
m2 =[1 1;0 0];
m3=[2 2 2 2 ;3 3 3 3];
C = {m1,m2,m3};
[r,c] = cellfun(@size,C);
m = max([r(:),c(:)]);
for ii = 1:numel(C)
if any([r(ii),c(ii)] < m)
C{ii}(m(1),m(2)) = 0;
end
end
out = cat(1,C{:})

추가 답변 (1개)

Moe_2015
Moe_2015 2017년 7월 26일
편집: Moe_2015 2017년 7월 26일
One solution:
Matrix1 = [ 2 2; 0 0];
Matrix2 = [1 1;0 0];
Matrix3 = [2 2 2 2;3 3 3 3];
[reshape(Matrix1',1,4);zeros(1,4);reshape(Matrix2',1,4);zeros(1,4);Matrix3]
  댓글 수: 2
Gratitude Kim
Gratitude Kim 2017년 7월 26일
Thanks a lot.
Moe_2015
Moe_2015 2017년 7월 26일
No problem!

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

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by