필터 지우기
필터 지우기

Create matrix from combination of two other matrices

조회 수: 3 (최근 30일)
Andrew Alkiviades
Andrew Alkiviades 2012년 5월 11일
Hi
I have two types of matrices that I need to add together. One has 5 (365x24) matrices and the other has 10 (365x24) matrices. I am trying to create a third matrix that has all the possible combinations of a sum of two types above. Therefore I need to code to create 50 matrices (again 365x24) that sums both elements in the same position
Does anyone have any idea where to start?
Thank you

채택된 답변

Andrei Bobrov
Andrei Bobrov 2012년 5월 11일
eg:
Mtype1 = arrayfun(@(ii)randi(randi([5 10]),5),(1:5).','un',0);
Mtype2 = arrayfun(@(ii)randi(randi([10 50]),5),(1:10).','un',0);
% solution
[ii,jj] = ndgrid(1:numel(Mtype1),1:numel(Mtype2));
out = cellfun(@(x,y)x + y,Mtype1(ii(:)),Mtype2(jj(:)),'un',0);
or:
ij = fullfact([5 10]);
out = cellfun(@(x,y)x + y,Mtype1(ij(:,1)),Mtype2(ij(:,2)),'un',0);

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Sparse Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by