Prohibit "pcg" writing to command window

Hello,
I got a more cosmetic question concerning matlab function "pcg" https://de.mathworks.com/help/matlab/ref/pcg.html. Is there a way to prevent a command line output from pcg after each (un)successful call? It is annoying and might even slow my program down due to the writing to the command window. Thanks in advance, Daniel

4 件のコメント

Geoff Hayes
Geoff Hayes 2018 年 7 月 4 日
Daniel - you may want to post the line of code that you are using to call pcg and an example of the unsuccessful command line output from that call. Do you have a semi-colon at the end of your line of code? Do you observe particular warnings that you wish to suppress (via https://www.mathworks.com/help/matlab/matlab_prog/suppress-warnings.html)? Please clarify.
Daniel Döhring
Daniel Döhring 2018 年 7 月 4 日
Hi Geoff,
I use the pcg solver for an implicit euler with a linear right-hand side:
for i=1:nts-1
U(:,i+1)=pcg(Id-(tspan(i+1)-tspan(i))*A, U(:,i));
end
and since nts = number time steps might be very large, I do not want to see every message of a successful pcg solve at the command line. Best, Daniel
Geoff Hayes
Geoff Hayes 2018 年 7 月 5 日
Daniel - what does the output of a successful call look like?
Daniel Döhring
Daniel Döhring 2018 年 7 月 5 日
My whole command winwo is full of these messages, is there a way to suppress these messages?

サインインしてコメントする。

 採用された回答

Geoff Hayes
Geoff Hayes 2018 年 7 月 5 日

0 投票

Daniel - Wow that is busy. Perhaps try doing
[x,~,~,iter] = pcg(Id-(tspan(i+1)-tspan(i))*A, U(:,i));
U(:,i+1) = x;
I noticed that if I just did
[x] = pcg(Id-(tspan(i+1)-tspan(i))*A, U(:,i));
then I would observe the pcg converged at ... message. But with the other line of code where I have an iteration output parameter, iter, then the message is suppressed.

2 件のコメント

Daniel Döhring
Daniel Döhring 2018 年 7 月 5 日
This works out, thanks!
Josh Meyer
Josh Meyer 2019 年 9 月 23 日
To clarify for future readers: if you specify the second FLAG output then the function stops printing convergence information to the command window. Instead the value of the FLAG output conveys whether the attempt was successful.
[x,flag] = pcg(...)

サインインしてコメントする。

その他の回答 (0 件)

製品

リリース

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by