필터 지우기
필터 지우기

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

조회 수: 6 (최근 30일)
FS
FS 2024년 6월 14일
편집: FS 2024년 6월 14일
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에서 Characters and Strings에 대해 자세히 알아보기

제품


릴리스

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by