let's say i have 500 units and i want to move those units to A and B. how to separate those units by percentage 60 to A and 40 to B ??

2 个评论

Could you please elaborate by what you mean by units? Would it be a matrix or something like a table with multiple groups?
matrix btw
thank you for respon

请先登录,再进行评论。

 采纳的回答

KSSV
KSSV 2021-9-7
编辑:KSSV 2021-9-7
X = rand(1,100) ; % say your data or units
n = length(X) ;
% move in the order
A = X(1:60/100*n) ;
B = X(60*n/100+1:end) ;
% move in randomly
idx = randperm(n) ; % randomly arrange the indices
A = X(idx(1:60/100*n)) ;
B = X(idx(60*n/100+1:end)) ;

3 个评论

Wow , Thank you so much bro
"move in randomly" is wrong i think
CMIIW
Yes... Indices idx should be used. Edited the code.

请先登录,再进行评论。

更多回答(0 个)

类别

在 帮助中心 和 File Exchange 中查找有关 Logical 的更多信息

产品

版本

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by