How can i divide a (matrix) into two parts

조회 수: 1 (최근 30일)
maryam
maryam 2015년 2월 23일
댓글: maryam 2015년 2월 24일
i have a 300*10 matrix. i want to divide it into two parts. the size of desired parts are 240*10 and 60*10 respectively.
A=[]10*300 % is given
B=[]10*240 % i can generate it
C=[]10*60 % i need help in this part, columns of matrix A which are not in matrix B should produce matrix C
would you give me an advice?thank you very much
  댓글 수: 3
maryam
maryam 2015년 2월 23일
편집: maryam 2015년 2월 24일
this is how i generate B:
idx=randsample(300,240);
idx=idx';
for i=1:240;
B(:,i)=A(:,idx(i));
end
i want rest of matrix A columns produce matrix C
dpb
dpb 2015년 2월 23일
This doesn't do what you say you want...you say you want B and C with 10 columns; you've loaded B as 240x240 as the above is written.
Clarify what you really do mean, precisely.

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

채택된 답변

Andrei Bobrov
Andrei Bobrov 2015년 2월 23일
편집: Andrei Bobrov 2015년 2월 24일
idx=randsample(300,240);
or
idx = randperm(300,240);
B = A(idx,:);
C = A(~ismember((1:size(A,1))',idx),:); %
or
C = A(setdiff((1:size(A,1))',idx),:);
or
C = A(setxor(1:size(A,1),idx),:);
  댓글 수: 1
maryam
maryam 2015년 2월 24일
thank you for your help, it works :)

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

추가 답변 (1개)

dpb
dpb 2015년 2월 23일
편집: dpb 2015년 2월 23일
Hard as James says to envision how you could do B and not be able to figure out C but
C=A(241:end,:);
Mayhaps it's end you were struggling with altho the workaround w/o the "syntactic sugar" of the builtin function isn't hard...
C=A(241:size(A,1),:);
or use an intermediary variable.
[nRow,nCol]=size(A);
ADDENDUM
OK, so you want a random permutation of the rows...
...scratch previous, it solves the problem I thought was asked for but the asking is conflicting in dimensions with the proposed example partial solution...
  댓글 수: 1
maryam
maryam 2015년 2월 23일
please notice to my above reply. do you have any suggestion?

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

카테고리

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