Continue displaying output using disp() function
15 次查看(过去 30 天)
显示 更早的评论
I use disp() in a live script function to track which samples in a data set have been processed in a parfor loop. However, when long enough, the disp() out put will be something like this:
Sample 300 has been processed.
Sample 301 has been...
and will no longer output.
I've looked around and can't seem to how to remove an output limitation. Is there a way to increase/unlimit this or is it immutable?
7 个评论
Sindar
2020-6-1
编辑:Sindar
2020-6-1
I don't think this is the same problem since we are far below that limit (~6e4 characters) and that has to do with printing to files vs livescript output. Also, note that running the test in the command line prints everything for me.
It seems most likely that your issue is butting against the livescript's intent to avoid doing things like accidentally outputting huge arrays. But, it seems like there should be a way around it
采纳的回答
K.
2020-10-14
In this case, your code is hitting a 60,000 character limit per output. This particular limit is part of the Live Editor, and unfortunately, there is no way to change it. Our development team will take this as feedback, and we hope to address it in a future release.
That being said, there might be some ways you can work around this limit. Although I’m not sure they’ll meet your needs, as the first two don’t work with parfor.
Workaround 1:
The Live Editor automatically groups textual output from the same line into a single output. That means that if we introduce some other output on a different line, we can have multiple outputs, each with their own 60,000 character limit. Here is a crude example that demonstrates this. The output doesn’t look so nice, but you can see all the progress.
for ind=1:10000
if (mod(ind, 1000) == 0)
disp('--')
end
disp(['Sample ', int2str(ind), ' has been processed'])
end
![Result of Workaround 1](https://www.mathworks.com/matlabcentral/answers/uploaded_files/380506/Result%20of%20Workaround%201.png)
Workaround 2:
Some people have used the ‘\b’ (backspace) character to create textual progress indicators (e.g. https://blogs.mathworks.com/loren/2007/08/01/monitoring-progress-of-a-calculation/). I believe there are some tools for this on File Exchange, but as an example, you could do something like the following. Once again, it is a crude example only meant to demonstrate the concept.
for ind=1:20
pause(.1)
printStatus(ind) % Do the fprints in a local function so that all the textual output is coming from one line in the script.
end
function printStatus (ind)
if ind == 1
% The very first time we don't need to delete the old text
fprintf('Last processed sample: %5d', ind);
else
% Each \b removes one character from the previous fprintf.
fprintf('\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\bLast processed sample: %5d', ind);
end
end
![Results of Workaround 2](https://www.mathworks.com/matlabcentral/answers/uploaded_files/380511/Results%20of%20Workaround%202.gif)
Workaround 3:
Since the textual output for the entire parfor is treated as one output and hence subject to the 60,000 character limit, you could potentially split up your work into a few parfors on separate lines:
parfor ind=1:1000
doStuff(ind);
end
parfor ind=1001:2000
doStuff(ind);
end
function doStuff(ind)
disp(['Sample ', int2str(ind), ' has been processed'])
end
![Results of Workaround 3](https://www.mathworks.com/matlabcentral/answers/uploaded_files/380516/Results%20of%20Workaround%203.png)
Not a great solution, but sharing just in case.
I hope this helps, and as I said earlier, we hope to address this in a future release.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Entering Commands 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!