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

25 ビュー (過去 30 日間)
Lockywolf
Lockywolf 2018 年 12 月 10 日
コメント済み: Walter Roberson 2018 年 12 月 10 日
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

採用された回答

Walter Roberson
Walter Roberson 2018 年 12 月 10 日
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 件のコメント
Lockywolf
Lockywolf 2018 年 12 月 10 日
Wow! That's exactly the solution!

サインインしてコメントする。

その他の回答 (2 件)

KSSV
KSSV 2018 年 12 月 10 日
USe fprintf
a = 5 ;
fprintf(' %f\n',a)
  1 件のコメント
Walter Roberson
Walter Roberson 2018 年 12 月 10 日
Trees of objects tends to suggest that the inputs are not necessarily numeric .

サインインしてコメントする。


madhan ravi
madhan ravi 2018 年 12 月 10 日
Just use fprintf() or sprintf()
a=5;
fprintf(' a=\n')
fprintf(' %d\n',a)

カテゴリ

Help Center および File ExchangeData Type Identification についてさらに検索

製品


リリース

R2013a

Community Treasure Hunt

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

Start Hunting!

Translated by