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에서 Loops and Conditional Statements에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!