align created random numbers in an array

2 visualizzazioni (ultimi 30 giorni)
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!

Risposta accettata

Wayne King
Wayne King il 12 Giu 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

Più risposte (0)

Categorie

Scopri di più su Get Started with Statistics and Machine Learning Toolbox in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by