move data in randomly

2 ビュー (過去 30 日間)
Takim Mustakim
Takim Mustakim 2021 年 9 月 7 日
コメント済み: Takim Mustakim 2021 年 9 月 8 日
suppose I have a 1 x 10 matrix : [ 1 3 2 5 4 7 6 9 8 0] and want to move it to A and B how to randomly move the dataset by generating output percentages of 60 A and 40 B.
Example output : A : [ 1 2 5 7 8 0 ] and B : [ 3 4 6 9 ]

回答 (1 件)

Image Analyst
Image Analyst 2021 年 9 月 8 日
See this well commented solution:
% Create sample data.
v = [ 1 3 2 5 4 7 6 9 8 0]
% Find out how many values we need to send to A.
numIndexes = round(0.6 * length(v))
% Get random indexes.
AIndexes = randperm(length(v), numIndexes);
% Extract those indexes from v and put them into a new vector called A
A = v(AIndexes)
% Whatever is in v that is not already in A, put those into B using setdiff()
B = setdiff(v, A)
  1 件のコメント
Takim Mustakim
Takim Mustakim 2021 年 9 月 8 日
thank you so much bro

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

製品


リリース

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by