Effacer les filtres
Effacer les filtres

How can i divide a (matrix) into two parts

1 vue (au cours des 30 derniers jours)
maryam
maryam le 23 Fév 2015
Commenté : maryam le 24 Fév 2015
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 commentaires
maryam
maryam le 23 Fév 2015
Modifié(e) : maryam le 24 Fév 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 le 23 Fév 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.

Connectez-vous pour commenter.

Réponse acceptée

Andrei Bobrov
Andrei Bobrov le 23 Fév 2015
Modifié(e) : Andrei Bobrov le 24 Fév 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),:);
  1 commentaire
maryam
maryam le 24 Fév 2015
thank you for your help, it works :)

Connectez-vous pour commenter.

Plus de réponses (1)

dpb
dpb le 23 Fév 2015
Modifié(e) : dpb le 23 Fév 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 commentaire
maryam
maryam le 23 Fév 2015
please notice to my above reply. do you have any suggestion?

Connectez-vous pour commenter.

Catégories

En savoir plus sur Creating and Concatenating Matrices dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by