Can I change the prompt in MATLAB?

大城市里の小女人 提交于 2019-12-19 05:19:12

问题


I never work with the GUI and am always inside a terminal (also full screen, so no title bar) set with the -nodesktop -nodisplay option. I also have different servers that I connect to, to run matlab and each of those have different restrictions on hogging computational resources. Since it's hard to remember which server I'm in,especially if I have multiple sessions open, I was wondering if I could change the prompt to display the server name. Try as I might, I couldn't find a resource that explains how to go about it (I'm beginning to think Mathworks doesn't support it). I know, a workaround would be to simply write a function call to system('hostname') and put the function in the path, so that it's about as easy as typing pwd to find the directory. I'd like to know if there's something more elegant.


回答1:


There is a submission on the MathWorks File Exchange that can do this for you: setPrompt by Yair Altman. Using it in R2010b, I noticed that I was getting the warning message:

Warning: Possible deprecated use of set on a Java callback. 
> In setPrompt at 115

Which I was able to suppress using the warning function like so:

warning('off','MATLAB:hg:JavaSetHGProperty');

And here's how I changed the prompt to the host name using the system function:

>> [~,systemString] = system('hostname');
>> setPrompt([deblank(systemString) '>> ']);
P11-4504>>

The function deblank is used to remove trailing whitespace (in this case a newline) from the string.

NOTE: The above changes (suppressed warning and modified prompt) don't persist after you quit and restart MATLAB, so you could put the above code in your startup.m file to apply them automatically every time you start a new session.



来源:https://stackoverflow.com/questions/5048889/can-i-change-the-prompt-in-matlab

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!