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!

采纳的回答

Wayne King
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 个)

类别

Help CenterFile 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!

Translated by