Divide the matrix randomly, based on columns
2 次查看(过去 30 天)
显示 更早的评论
采纳的回答
Rik
2019-12-11
You mean like this?
fractions=[70 15 15];
x=rand(78000,100);%use 100 to show the split is indeed 75:15:15
groups=cell(size(fractions));%pre-allocate output
f=fractions/sum(fractions);
f=[0 cumsum(f)];
r=randperm(size(x,2))/size(x,2);
for n=1:numel(groups)
L= r>f(n) & r<=f(n+1);
groups{n}=x(:,L);
end
2 个评论
Rik
2019-12-11
Because randperm is generating the indices, this is guaranteed not to result in overlapping groups. Unless there are columns in your data that are equal to eachother, there is not be any match between the groups.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Creating and Concatenating Matrices 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!