Storing each realization as a variable
Mostrar comentarios más antiguos
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!
Respuestas (2)
John D'Errico
el 28 de Oct. de 2016
Editada: John D'Errico
el 28 de Oct. de 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
el 28 de Oct. de 2016
yi=cell(100,1);
for i:1=100
yi{i}=5*randn(1,10000)+2;
end
Categorías
Más información sobre Logical en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!