Storing each realization as a variable
Show older comments
Hi,
I want to generate many realizations of different distributions and store each realization as a variable. For example, let's say I want to generate 100 different realizations of the function randn with mean=2 and std=5, where each realization has 10,000 points. How would I write the loop? So far I have:
x=cell(100,1);
for i:1=100
x{i}=5*randn(1,10000)+2;
y(i)=x{i};
end
I know this generates a cell. I would like to name each yi as each of the 100 realizations. Thanks!
Answers (2)
John D'Errico
on 28 Oct 2016
Edited: John D'Errico
on 28 Oct 2016
You are asking to store a vector of length 10000 in a single element of a numeric, double precision array. NOT possible. Perhaps you are thinking of a pointer of some sort. Again, NOT possible. MATLAB does not provide pointers.
Nothing stops you from storing the entire mess in one array, of size 100x10000.
y = 5*randn(100,10000)+2;
Then you will access the k'th vector as simply
y(k,:)
I fail to see the problem with that. If it REALLY bothers you, then use a structure array, or leave them as a cell array, but that just adds a bit more complexity to the problem. So why do it?
KSSV
on 28 Oct 2016
yi=cell(100,1);
for i:1=100
yi{i}=5*randn(1,10000)+2;
end
Categories
Find more on Logical in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!