Datasample將更好地服務,只要您使用非替換形式(我猜你不想重複輸出。如果你確定這一說法,則忽略該「替換」標誌)。該指數的輸出也將是未排序的,這樣你就可以完美地將它用於數據2:
data1 = [a b c d e];
data2 = [f g h i j]
[out1,idx] = datasample(data1,k,'Replace',false);
out2=data2(idx);
我看你也是「只需要以隨機抽取更多1500的第三剩餘的2760,然後,剩餘的1260 。矢量「,你可以使用IDX信息不理那一套:
idx_notused=setdiff(1:size(data1,1),idx); %finds all positions not selected previously
[out1_v2,idx2] = datasample(data1(idx_notused),k,'Replace',false); %k=1500
idx2=idx_notused(idx2); %so it maps with the original data
out2_v2=data2(idx2);
%and again for the remaining 1260:
idx_remaining=setdiff(1:size(data1,1),[idx idx2]);
out1_v3=data1(idx_remaining);
out2_v3=data2(idx_remaining);
來源
2017-02-17 21:25:47
ana
用於與第二輸出數據1使用datasample還捕獲。使用數據採樣的第二個輸出來索引data2和其他數據。 – Navan
您是否選擇**並帶**或**而不帶**替換? – rayryeng
我在沒有但沒有成功的情況下使用,但@TonyTannous提供的解決方案工作。但是,如果可能的話,我需要做一些更復雜的事情。我正確地提取了可以說的8760個數字中的6000個,但我需要隨機提取更多1500 ** **其餘2760個,然後剩下的1260個第三個向量。他想要獨特的@rayryeng – Paulos