MATLAB Answers

Print a statement to the Command Window

17,171 views (last 30 days)
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?


Sign in to comment.

Accepted Answer

KSSV on 5 May 2017
Edited: MathWorks Support Team on 27 Feb 2020
To display text in the Command Window, use disp or fprintf.
disp('job done')
fprintf('job done \n')


Sign in to comment.

More Answers (1)

Gaurav Srivastava
Gaurav Srivastava on 26 May 2019
It's not happening. How to display LHS=RHS?Screenshot (9).png


Christopher Johnston
Christopher Johnston on 21 Jun 2019
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 on 21 Jun 2019
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.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!