フィルターのクリア

How can i divide a (matrix) into two parts

2 ビュー (過去 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 Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by