필터 지우기
필터 지우기

create matrix again.....need help...please

조회 수: 1 (최근 30일)
andy ganteng
andy ganteng 2011년 11월 11일
I have 2 matrices, A(10,10) and B(10,20). which have same size in row and different in column because matrix A consist of 10 variables, which each variables have different size in column. and the column size depend on user input (in matrix), if the input are [1 1 2 1 2 1 1 2 1 1] then matrix A have 13 column. matrix B also consist of 10 variables, column size in matrix B depend on user input either, if the input is 2 then each variables have the same size of column (2), and the total matrix B have 2*10=20 column.
Now,i wanna create matrix C which consist of A and B with the structure like this C=[A(:,1) B(:,1:2) A(:,2) B(:,3:4) A(:,3:4) B(:,5:6) A(:,5) B(:,7:8) A(:,6:7) B(:,9:10) A(:,8) B(:,11:12) A(:,9) B(:,13:14) A(:,10:11) B(:,15:16) A(:,12) B(:,17:18) A(:,13) B(:,19:20)].
this question is rather similar to my question before, but both matrice have the same size before.please help.
thanks in advance.

채택된 답변

Andrei Bobrov
Andrei Bobrov 2011년 11월 11일
A = randi([100 200],10,10);
B = randi(99,10,20);
a = [1 1 2 1 2 1 1 2 1 1];
b = 2;
k1 = arrayfun(@(i1)A(:,i1*ones(a(i1),1)),1:size(A,2),'un',0);
k2 = mat2cell(B,size(B,1),ones(size(B,2)/b,1)*b);
out = cell(1,numel(k1)*2);
out(1:2:end) = k1;
out(2:2:end) = k2;
out = cell2mat(out);
or
out = cell2mat(reshape([k1;k2],1,[]))
  댓글 수: 1
andy ganteng
andy ganteng 2011년 11월 11일
it works.....thank you very much

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

추가 답변 (0개)

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by