我可以在MATLAB中更改提示吗? [英] Can I change the prompt in MATLAB?

查看:104
本文介绍了我可以在MATLAB中更改提示吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从不使用GUI,并且总是在使用-nodesktop -nodisplay选项设置的终端(也为全屏显示,因此没有标题栏)内.我还连接了不同的服务器以运行matlab,每个服务器在占用计算资源方面都有不同的限制.由于很难记住我所在的服务器,特别是如果我打开了多个会话,因此我想知道是否可以更改显示服务器名称的提示.尽我所能,我找不到解释其操作方法的资源(我开始认为Mathworks不支持它).我知道,一种解决方法是简单地对system('hostname')编写函数调用,然后将函数放在路径中,这样就和键入pwd来查找目录一样容易.我想知道是否还有更优雅的东西.

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.

推荐答案

MathWorks File Exchange 可以为您完成此操作: Yair Altman 中的nofollow noreferrer> setPrompt .在R2010b中使用它,我注意到我收到警告消息:

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

使用 warning 像这样的功能:

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

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

这是我使用 功能:

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

函数 deblank 用于删除结尾的空格(在本例中为换行符).

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

注意:在退出并重新启动MATLAB之后,上述更改(禁止的警告和修改的提示)不会继续存在,因此您可以将以上代码放入

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.

这篇关于我可以在MATLAB中更改提示吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆