Azzera filtri
Azzera filtri

How can i divide a (matrix) into two parts

1 visualizzazione (ultimi 30 giorni)
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 Commenti
maryam
maryam il 23 Feb 2015
Modificato: maryam il 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 il 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.

Accedi per commentare.

Risposta accettata

Andrei Bobrov
Andrei Bobrov il 23 Feb 2015
Modificato: Andrei Bobrov il 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),:);

Più risposte (1)

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

Accedi per commentare.

Categorie

Scopri di più su Creating and Concatenating Matrices in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by