Storing each realization as a variable

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!

回答(2 个)

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?

类别

帮助中心File Exchange 中查找有关 Logical 的更多信息

标签

提问:

2016-10-28

回答:

2016-10-28

Community Treasure Hunt

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

Start Hunting!

Translated by