MATLAB Answers

Simulink callbacks not displaying text in MATLAB command window

93 ビュー (過去 30 日間)
Mike
Mike 2015 年 2 月 10 日
編集済み: Stefanie Schwarz 2019 年 7 月 3 日
Typically I add the following callbacks to all of my Simulink models which displays the simulation start time, end time, and elapsed time in the main command window.
StartFcn:
TS = clock;
TS_dis = ['Simulation Start Time: ' datestr(clock)];
disp(TS_dis)
StopFcn:
TE = clock;
TE_dis = ['Simulation End Time: ' datestr(clock)];
disp(TE_dis)
Elapsed_Time = etime(TE,TS);
T_Min = floor(Elapsed_Time/60);
T_Sec = rem(Elapsed_Time,60);
TElap_disp = ['Elapsed Simulation Time: ' num2str(T_Min) ' Minutes ' num2str(T_Sec) ' Seconds'];
disp(TElap_disp)
This code has worked well up to 2014a however in 2014b this code outputs to the diagnostics viewer which is much less convenient. Is there any way to change where the disp() command outputs text to?
Thanks,
Mike

  0 件のコメント

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

採用された回答

Stefanie Schwarz
Stefanie Schwarz 2019 年 7 月 3 日
This output redirection is occurring due to the introduction of Diagnostic Viewer in R2014a.
Please see below MATLAB Answers Post for details and possible workarounds:

  0 件のコメント

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

その他の回答 (5 件)

Sean de Wolski
Sean de Wolski 2015 年 7 月 30 日
fprintf(2,'Hello World')
Will pipe to the command line in red (standard error).

  1 件のコメント

Jim Johnson
Jim Johnson 2016 年 5 月 17 日
I had the same issue, the callback would output to the command window in R2014b but not in R2015b. So I used the fprintf(2,'Displayed Text') solution and it does output to the command window but in RED as if it is an error. Is there some way to circumvent this, e.g., tell fprintf to print to the command window instead of the standard error such as fprintf(command_window,'Displayed Text')?? Mathworks could define their version of fprintf to use 3 as command window and thus fprintf(3,'Displayed Text') would work.

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


David Brown
David Brown 2017 年 4 月 20 日
To all,
This is kind of an old thread but I ran into the same problem and found a solution that works for me. Yair Altman created a function called cprintf that can be used instead of fprintf to print colored text to the command window. I tried cprintf with R2014a in a block callback and it sent the text to the command window. I haven't tried later versions of Matlab but I suspect that it works in later releases as well. To make it look like fprintf just use 'black' as the first parameter.
The cprintf utility is available through the FEX here:
Thanks Yair.
DJB

  0 件のコメント

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


Mohamed Elattal
Mohamed Elattal 2017 年 7 月 7 日
編集済み: Mohamed El-Attal 2017 年 7 月 7 日
Just migrated to 2016b. This is quite an annoying change!!! disp has been there since forever and changing its behaviour from model callback without a backward compatibility variant is completely unjustified!!
fprintf(2,..) doesn't do the trick.
Text is in red except the last character!
Text is displayed before the command input >>
Warning and error messages are displayed in diagnostics viewer, so information is again split.

  1 件のコメント

Stefanie Schwarz
Stefanie Schwarz 2019 年 7 月 3 日
If you add a newline escape sequence (\n), the entire text will be red and ">>" appears in a new line:
fprintf(2, 'Test message.\n');

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


Michael
Michael 2017 年 8 月 31 日
This is really an annoying change! Give us disp directed to the command window for simulink callbacks back!

  0 件のコメント

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


Mark Mears
Mark Mears 2017 年 10 月 21 日
Old thread... still annoying... still not addressed anywhere I can find. Is there any other way to use "disp" to print results to the command window? Is there some other way to have Simulink callbacks help output data?

  0 件のコメント

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

タグ

製品

Community Treasure Hunt

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

Start Hunting!

Translated by