parfor iteration counter display: dynamic \n at EOL?

5 Ansichten (letzte 30 Tage)
Matlabber 1.0
Matlabber 1.0 am 13 Nov. 2017
Kommentiert: Walter Roberson am 13 Nov. 2017
dear all, I made myself a function that compactifies the counter output line display in loops, and it works like a charm:
function [ output_args ] = f_CompactCount(c,f,r,d)
% compactifies commandline counter printing
% c = counter
% f = only every f-th number printed
% r = amount of counter displays per line
% d = digits per number
if mod(c,f)==0;
string=strcat('%',num2str(d),'.d');
if mod(c,r*f)==0
fprintf(strcat(string,'\n'),c)
else
fprintf(string,c)
end
end
end
it prints out every f-th counter number, r times per line of output and d digits (incl. space) per counter print. After the r-th time, at the end of a line, a new line is started.
Now, if i use this in par for loops, it is messed up since the counter follows a random sequence. How can I modify this counter display such that a line break occurs after r counter prints?
[edit] my idea would be to check how long the current command line output is and create a new line based on that or something

Akzeptierte Antwort

Jan
Jan am 13 Nov. 2017
You use parfor to run the different jobs independently in parallel. Now you want, that the threads communicate with each other for a coordinated output to the command window.
You find some progressbars for parfor in the file exchange: https://de.mathworks.com/matlabcentral/fileexchange/?utf8=%E2%9C%93&term=parfor. Some use a communication through files, what is a really bad idea. E.g. this looks stable: https://de.mathworks.com/matlabcentral/fileexchange/24594-parfor-progress-monitor. Perhaps you can modify it to support an output to the command window.
  1 Kommentar
Walter Roberson
Walter Roberson am 13 Nov. 2017
With R2017a or later you can use a data queue or pollable data queue to send data back. See afterEach()

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by