Problem statement:- I want to create 50 instances of a vector(1 Dimension) which contains random real numbers(float). The array size(1 dimension) will be say 30 thousand.How do i proceed so that the overhead is minimum or complexity is minimum?
Problem statement:- I want to create 50 instances of a vector(1 Dimension) which contains
Share
In the example above you will generate a matrix, in which every row is a single vector. Random numbers are generated with uniform distribution (for Gaussian distribution, use
randn).If you need to create every instance separately use a loop:
But I wouldn’t use that if I were you (it is slower and IMHO less clear).
EDIT:
Regarding your question under Mau’s answer:
No, you don’t need to index it on your own. Let Matlab do it for you.
For example, if you need to repeat following operation 50 times:
assuming
yis a vector of size 1×30000, you can compute it in one line:explanation:
every row is a single vector you wanted to compute:
repmat(y,50,1)repeats youryvector 50 times in first dimension (rows)