I am writing a program. I want to display the statement 'job done' as the output in the Command Window. How can I do it?

댓글 수: 2

3)What is the command that writes a message to the screen?
Hai navneet nayan,
disp('job done');
disp command is used display the string values.

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

 채택된 답변

KSSV
KSSV 2024년 11월 13일
편집: MathWorks Support Team 2024년 11월 13일

21 개 추천

To display text in the Command Window, use disp or fprintf .
disp('job done')
or
fprintf('job done \n')

댓글 수: 3

John Taranto
John Taranto 2023년 3월 23일
I would not mark this as an accepted answer since it does not solve the problem I detailed.
Hi John,
There is no way to direct output to the Command Window from a live script that you run in the Live Editor.
You can run the live script from the command line; e.g., if your file is myScript.mlx, then
>> myScript
will indeed output to the Command Window (and separate figure windows). But again there's no way to redirect output from the Live Editor. This is something we are investigating, however.
Jared
Justin Bell
Justin Bell 2023년 7월 18일
I just wanted to bump some support for such a feature with live editor. with some larger scripts that can take up to hours of runtime it would be nice to be able to push a "N% complete" or "Error Detected" flag to the window. Not required but would be nice to be able to have the same color options matlab uses for the command window, i.e. disp in default text options with a vargin for red text etc.

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

추가 답변 (2개)

Gaurav Srivastava
Gaurav Srivastava 2019년 5월 26일

1 개 추천

It's not happening. How to display LHS=RHS?Screenshot (9).png

댓글 수: 3

As mentioned by KSSV, you can use fprintf.
For the variables you have shown above:
fprintf('a = %.4f \nb = %.4f \nx = %.4f \n', a, b, x)
This example allows you to print to 4 fixed points of precision, but this can be tailored to your need by changing the number after the '%.' .
Steven Lord
Steven Lord 2019년 6월 21일
Even though a and b are displayed the same, that doesn't mean their contents are the same. The == operator checks for exact down-to-the-last-bit equality. In this case, a and b are close but close doesn't count. See this Answers post for an alternative.
Try to make a diference between a and b with a tolerance
tol = 1e-3
if abs(a - b) < tol
disp('LHS=RHS')
end

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

Dhritishman
Dhritishman 2022년 7월 10일
Use the disp function to print to the command window:
disp('job done')
job done

댓글 수: 3

John Taranto
John Taranto 2022년 12월 20일
Please help me understand this. I use Live Scripts to write my Matlab code. There is a window titled Live Editor - with the path to the mlx file. Separately, there is a Command Window. When I use either the disp() or fprintf() function the output is to the Live Editor Window. I would like to output to the Command Window. How would I do that?
Thanks.
Jack
Jack 2023년 3월 23일
I agreen with @John Taranto. On a .mlx script disp or fprint do not return anything in Command Window, instead it is returned directly underneath the code or to the side depending on your setting. Is there a way to force the text to be displayed in the command window? Thank you in advance
Hi Jack,
There is no way to direct output to the Command Window from a live script that you run in the Live Editor.
You can run the live script from the command line; e.g., if your file is myScript.mlx, then
>> myScript
will indeed output to the Command Window (and separate figure windows). But again there's no way to redirect output from the Live Editor. This is something we are investigating, however.
Jared

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

카테고리

도움말 센터File Exchange에서 Entering Commands에 대해 자세히 알아보기

태그

아직 태그를 입력하지 않았습니다.

질문:

2017년 5월 5일

편집:

2024년 11월 13일

Community Treasure Hunt

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

Start Hunting!

Translated by