How can i divide a (matrix) into two parts

1 view (last 30 days)
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 Comments
maryam
maryam on 23 Feb 2015
Edited: maryam on 24 Feb 2015
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 on 23 Feb 2015
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.

Sign in to comment.

Accepted Answer

Andrei Bobrov
Andrei Bobrov on 23 Feb 2015
Edited: Andrei Bobrov on 24 Feb 2015
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),:);

More Answers (1)

dpb
dpb on 23 Feb 2015
Edited: dpb on 23 Feb 2015
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 Comment
maryam
maryam on 23 Feb 2015
please notice to my above reply. do you have any suggestion?

Sign in to comment.

Categories

Find more on Creating and Concatenating Matrices in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!