align created random numbers in an array
2 ビュー (過去 30 日間)
古いコメントを表示
Hey
i want to align random samples that are of different lengths. I tried sth. like this
for i=1:length(N); U=rand(1,N(i,1)).*T; Y(1,i)=[U]; end;
so basically i have a vector N of size d x 1. For every row i want to draw random numbers and then align these random numbers in an array. Say the first creates [0.3, 0.7, 0.8] and the second [0.1, 0.2]. then Y should look like [0.3, 0.7, 0.1, 0.2]. This is because i don't know the exact length of U because N itself is a random number and then the dimensions of U would disagree! So i want that U creates this random sample and stores it in an array Y before doing the loop again. maybe somebody could help me with the correction of the code!
Thanks a lot!
0 件のコメント
採用された回答
Wayne King
2012 年 6 月 12 日
Y = [0.3, 0.7, 0.8];
U = [0.1 0.2];
Y = cat(2,Y,U);
or just
Y = [Y,U];
So for example:
N = [3 4 5];
Y = [];
for i = 1:length(N)
U = rand(1,N(i));
Y = cat(2,Y,U);
end
0 件のコメント
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Get Started with Statistics and Machine Learning Toolbox についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!