Retrive variable out of a parfor loop
5 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
andrea
am 19 Apr. 2020
Kommentiert: Thiago Henrique Gomes Lobato
am 19 Apr. 2020
I've got a simple problem, I run a parfor loop inside which i call a function which return some variables, the problem is that some of this variables does not show in the workspace.
0 Kommentare
Akzeptierte Antwort
Thiago Henrique Gomes Lobato
am 19 Apr. 2020
You have an error in your mont_carlo inputs, it should be
[x,neigh,E,M]= monte_carlo ( N, T, iter,init )
or you should delete the line
x = init ;
Besides this what exactly is the problem you're having? E and M should be showing in the workspace, since you gave it index to them. x and neigh are replaced in every loop in a random order, so no consistent result can be expected from them.
4 Kommentare
Thiago Henrique Gomes Lobato
am 19 Apr. 2020
When you have only one single value, those can be saved in a vector for each iteration, as the case with E and M. If you have a matrix, vector or anything different than a single number, it is not possible to attribute it's value to a single vector entry, so you have to use data structures that can handle it. Cell is just one of them, where you can save basically anything and then retrieve it with only the index.
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!