Hello, I want to use temporary variable value after parfor loop!, how can this achieved??
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
saddam alqasimi
am 29 Apr. 2019
Kommentiert: saddam alqasimi
am 17 Mai 2019
counter =0;
parfor i = 1:1000
max=999;
if max < i
max = i;
disp(max);
assignin('base','counter',max);
end
end
disp(counter);
For example, I want to keep max value but I got zero
2 Kommentare
Jan
am 29 Apr. 2019
This cannot work: 1. you assign the value to the variable counter in the base-workspace, but where does the posted code occur? Inside a function or a script? 2. The order of iterations is undefined in a parfor loop, but the final value depends on the last processed iteration. As consequence your code is equivalent to: randi([1,1000], 1). What do you want to achieve?
Akzeptierte Antwort
Walter Roberson
am 29 Apr. 2019
Create cmsc as a struct array of full size. Assign to cmsc(i) as appropriate. Also keep a logical vector used(i) =true where the condition is met. After the parfor cmsc = cmsc(used)
That graph might be more of a problem. Your code structure tends to hint that you are using information from previous iterations in updating the graph.
5 Kommentare
Walter Roberson
am 16 Mai 2019
You are calling Assign() and Kill() to update cmcs in ways that are not obvious. As outside observers, we would have to assume that the results are dependent upon the order of iterations.
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!