The error command wraps text to fit the width of the command window, but disp does not. I know I can put in hard-wired new lines with disp, but I do not want to assume that a user's command window is N characters wide. Is there a way to let text fit the command window dynamically as it does with error?

6 件のコメント

dpb
dpb 2014 年 8 月 17 日
AFAIK not automagically -- you would have to inquire for the screen size and I'm not sure under Matlab where that is--probably in there somewhere, but I'm not sure where.
There is the 'wrap lines' preference choice for the command window that does it, but whether there's a way to be less of a bludgeon than somehow mung the user's preferences I don't know.
Maybe a query for "Undocumented Matlab"???
Chad Greene
Chad Greene 2014 年 8 月 18 日
編集済み: per isakson 2015 年 9 月 24 日
Indeed, I did find an old Newsreader post wherein Yair suggested something along these lines:
InitialWrapSetting = com.mathworks.services.Prefs.getBooleanPref('CommandWindowWrapLines');
% com.mathworks.services.Prefs.setBooleanPref('CommandWindowWrapLines',1);
%
disp('A tall and good and not excessively rich and bald and very smart and good tall and tall and terrified and rich and not very terrified and smart and tall and young hamster insisted on it.')
%
com.mathworks.services.Prefs.setBooleanPref('CommandWindowWrapLines',InitialWrapSetting);
Unfortunately, it doesn't seem to work on my machine.
Jan
Jan 2014 年 8 月 18 日
"it does not seem to work" does not allow the readers to understand, what you observ. Which machine are you using and what happens?
Chad Greene
Chad Greene 2014 年 8 月 18 日
Hi Jan,
You're right; I was not very clear. I'm using OSX 10.8.5 with R2012b. By "it does not seem to work" I meant I get the same results (unwrapped lines) whether I declare
com.mathworks.services.Prefs.setBooleanPref('CommandWindowWrapLines',1);
before disp or not.
per isakson
per isakson 2014 年 8 月 18 日
With R2013a,64bit,Win7 your example outputs one long line. No word wrap here either. (And no warning or error message.)
dpb
dpb 2014 年 8 月 18 日
No joy w/ R2012b on XP, either. Interestingly enough,
>> com.mathworks.services.Prefs.getBooleanPref('CommandWindowWrapLines')
ans =
0
>> com.mathworks.services.Prefs.setBooleanPref('CommandWindowWrapLines',1)
>> com.mathworks.services.Prefs.getBooleanPref('CommandWindowWrapLines')
ans =
1
>>
Does make it appear there is such a option but whatever it does, disp "knows nuthnk!" about it...

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

 採用された回答

Chad Greene
Chad Greene 2015 年 9 月 23 日

0 投票

I ended up writing a function for this called wraptext.

その他の回答 (1 件)

dpb
dpb 2014 年 8 月 18 日

0 投票

Seems like reasonable enhancement request -- mayhaps TMW official support can suggest a workaround meanwhile.

カテゴリ

ヘルプ センター および File ExchangeStartup and Shutdown についてさらに検索

質問済み:

2014 年 8 月 17 日

編集済み:

2015 年 9 月 24 日

Community Treasure Hunt

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

Start Hunting!

Translated by