Effacer les filtres
Effacer les filtres

How can I indent the output of display() and disp()?

10 vues (au cours des 30 derniers jours)
Lockywolf
Lockywolf le 10 Déc 2018
Commenté : Walter Roberson le 10 Déc 2018
I am writing a small snippet to display trees of objects hierarchically.
I want to use standard Matlab functions as much as possible, therefore, I want to use disp() to display at least everything I don't care about implementing display() myself.
Is it possible to add, say, 10 spaces on the left of the output produced by disp(a)?
so that instead of:
>> a = 5
a =
5
I had
>> a = 5
a =
5

Réponse acceptée

Walter Roberson
Walter Roberson le 10 Déc 2018
You can evalc() the disp to get aa character vector with newlines in it. you can modify that to add the required number of spaces and then display the results
  1 commentaire
Lockywolf
Lockywolf le 10 Déc 2018
Wow! That's exactly the solution!

Connectez-vous pour commenter.

Plus de réponses (2)

KSSV
KSSV le 10 Déc 2018
USe fprintf
a = 5 ;
fprintf(' %f\n',a)
  1 commentaire
Walter Roberson
Walter Roberson le 10 Déc 2018
Trees of objects tends to suggest that the inputs are not necessarily numeric .

Connectez-vous pour commenter.


madhan ravi
madhan ravi le 10 Déc 2018
Just use fprintf() or sprintf()
a=5;
fprintf(' a=\n')
fprintf(' %d\n',a)

Catégories

En savoir plus sur Data Type Identification dans Help Center et File Exchange

Produits


Version

R2013a

Community Treasure Hunt

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

Start Hunting!

Translated by