How to output strings to the command window instead of live script?

30 次查看(过去 30 天)
Dear matlab community,
I asked a same question in Japanese(https://jp.mathworks.com/matlabcentral/answers/2127011-?s_tid=prof_contriblnk), but I couldn't get an answer to solve the issue, so I'm asking here.
I am writing a script in live script (.mlx).
When I use the functions in the live script including display/output processes using "disp" or "fprintf" function, many strings are output to the live script, impairing readability.
Is there a way to write some of the outputs to the command window or to another file instead of in the live script? Or is there a way to avoid some of them from being output?
I understand it would be easy to just delete the "disp" and "fprintf" in the function, but since the output is from a function in a distributed toolbox, so I would like to change my live script without modifying the function.
Also, I am adding a minimal script for this issue.
outputtest;
This is test output.
function [] = outputtest()
disp('This is test output.')
end
If it is written in .mlx as above, is it possible to change the output to the command window or another file?
Thank you in advance.

回答(1 个)

Shivani
Shivani 2024-6-14
Hello @FS,
From what I understand, there is no functionality in MATLAB that allows printing a statement in LiveScript directly to the Command Window.
This has been discussed in the following MATLAB Answer threads:
However, you can prevent the print or display statement from showing outputs amidst the lines of code by selecting the 'Output on Right' option. This action will print the lines of code in a separate window on the right, thereby maintaining good readability. I've highlighted this option in the screenshot below.
  1 个评论
FS
FS 2024-6-14
编辑:FS 2024-6-14
Dear @Shivani,
Thank you for your quick response and thank you for sharing the meaningful information!
Sure, there is currently no such function...
So, as an alternative idea, do you know a command to clear the output? It can be cleared from right-click in the GUI, but I would like to know the command.
I am looking for a disp version of clear or the "warning('off','all')" function.
I also understand the function that can output to the right side.
However, I would like to export the script to PDF as log file, so I would like to clear the strings from disp/fprintf when running the script.
Thank you for your help. 

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 MATLAB 的更多信息

产品


版本

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by