Print a statement to the Command Window
Show older comments
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 Comments
waleed Al-Qurashi
on 16 Feb 2021
3)What is the command that writes a message to the screen?
GOPINATHAN PRAKASH
on 20 Jun 2021
Hai navneet nayan,
disp('job done');
disp command is used display the string values.
Accepted Answer
More Answers (2)
Gaurav Srivastava
on 26 May 2019
1 vote
It's not happening. How to display LHS=RHS?.png)
.png)
3 Comments
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
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.
sidway
on 13 Aug 2021
Try to make a diference between a and b with a tolerance
tol = 1e-3
if abs(a - b) < tol
disp('LHS=RHS')
end
Use the disp function to print to the command window:
disp('job done')
3 Comments
John Taranto
on 20 Dec 2022
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
on 23 Mar 2023
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
Jared MacDonald
on 17 May 2023
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
Categories
Find more on Entering Commands in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!