我可以更改 MATLAB 中的提示吗?

发布于 2024-10-18 04:00:36 字数 322 浏览 1 评论 0 原文

我从不使用 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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

颜漓半夏 2024-10-25 04:00:36

MathWorks File Exchange 上有一个提交可以为您执行此操作:setPrompt 通过 Yair Altman。在 R2010b 中使用它时,我注意到收到了警告消息:

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

我可以使用 警告 功能如下:

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

以下是我如何使用 system 函数:

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

函数 deblank 用于从字符串中删除尾随空格(在本例中为换行符)。

注意:退出并重新启动 MATLAB 后,上述更改(抑制警告和修改提示)不会持续存在,因此您可以将上述代码放入 startup.m 文件 以在每次启动新会话时自动应用它们。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文