MATLAB Answers

Getting a command like gather to run silently

조회 수: 6(최근 30일)
KAE
KAE 20 Mar 2020
편집: Guillaume 27 Mar 2020
I am using the command gather many times in a loop, and it throws out the following updates each time,
Evaluating tall expression using the Local MATLAB Session:
- Pass 1 of 2: Completed in 1.5 sec
- Pass 2 of 2: Completed in 0.37 sec
Evaluation completed in 2 sec
Is there a way to make a command like this run silently?

  댓글 수: 1

KAE
KAE 20 Mar 2020
Let me see if evalc can be used on the line of my program that contains gather (see Walter's answer).

댓글을 달려면 로그인하십시오.

채택된 답변

Guillaume
Guillaume 27 Mar 2020
편집: Guillaume 27 Mar 2020
The following is unfortunately completely undocumented and therefore to be used at your own risk. It may stop working in a future version of matlab or may not even work in your version if you're not using R2020a which is where I've tested it:
%override default ProgressReporter (normally a CommandWindowProgressReporter) with a NullProgressReporter which displays nothing
matlab.bigdata.internal.executor.ProgressReporter.override(matlab.bigdata.internal.executor.NullProgressReporter);
It's a shame it's completely undocumented since mathworks have gone to the trouble of building this very complex machinery to completely change the way gather (and other functions) outputs progress.
Basically (sic! it's actually very complex with closures, futures, promises, lazy evaluators, executors, etc.) at some point gather will ask the abstract class ProgressReporter for the current progress reporter. By default it's a CommandWindowProgressReporter which is what displays the text to the command window. You can override that default with any other class derived from ProgressReporter and matlab provides such a class NullProgressReporter that outputs nothing.
It's a much better solution than using evalc and really mathworks should move it out of the internal package and document it.
Note: to go back to the default:
matlab.bigdata.internal.executor.ProgressReporter.override(matlab.bigdata.internal.executor.CommandWindowProgressReporter);
You can also create your own ProgressReporter to customise the progress display to your liking.

  댓글 수: 0

댓글을 달려면 로그인하십시오.

추가 답변(1개)

Sourabh Kondapaka
Sourabh Kondapaka 27 Mar 2020
Hi,
The evalc()” function can be used to suppress the output from a matlab expression and capture it in a variable.
The input to evalc()” function is a matlab expression as a string.
For more information, refer the documentation of 'evalc()' : evalc
For alternatives to using evalc()” function, refer :

  댓글 수: 0

댓글을 달려면 로그인하십시오.

태그

Community Treasure Hunt

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

Start Hunting!

Translated by