align created random numbers in an array

2 vues (au cours des 30 derniers jours)
Raphael
Raphael le 12 Juin 2012
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!

Réponse acceptée

Wayne King
Wayne King le 12 Juin 2012
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

Plus de réponses (0)

Catégories

En savoir plus sur Get Started with Statistics and Machine Learning Toolbox dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by