Print a statement to the Command Window

12 383 vues (au cours des 30 derniers jours)
NAVNEET NAYAN
NAVNEET NAYAN le 5 Mai 2017
Réponse apportée : mateo henao zapata le 21 Nov 2024 à 5:43
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 commentaires
waleed Al-Qurashi
waleed Al-Qurashi le 16 Fév 2021
3)What is the command that writes a message to the screen?
GOPINATHAN PRAKASH
GOPINATHAN PRAKASH le 20 Juin 2021
Hai navneet nayan,
disp('job done');
disp command is used display the string values.

Connectez-vous pour commenter.

Réponse acceptée

KSSV
KSSV le 13 Nov 2024 à 0:00
Modifié(e) : MathWorks Support Team le 13 Nov 2024 à 2:07
To display text in the Command Window, use disp or fprintf .
disp('job done')
or
fprintf('job done \n')
  3 commentaires
Jared MacDonald
Jared MacDonald le 17 Mai 2023
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 le 18 Juil 2023
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.

Connectez-vous pour commenter.

Plus de réponses (3)

Gaurav Srivastava
Gaurav Srivastava le 26 Mai 2019
It's not happening. How to display LHS=RHS?Screenshot (9).png
  3 commentaires
Steven Lord
Steven Lord le 21 Juin 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
sidway le 13 Août 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

Connectez-vous pour commenter.


Dhritishman
Dhritishman le 10 Juil 2022
Use the disp function to print to the command window:
disp('job done')
job done
  3 commentaires
Jack
Jack le 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
Jared MacDonald le 17 Mai 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

Connectez-vous pour commenter.


mateo henao zapata
mateo henao zapata le 21 Nov 2024 à 5:43

Catégories

En savoir plus sur Entering Commands dans Help Center et File Exchange

Tags

Aucun tag saisi pour le moment.

Community Treasure Hunt

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

Start Hunting!

Translated by