如何在Matlab提示中添加日期或时间戳? [英] How to add a date or timestamp to the Matlab prompt?

查看:935
本文介绍了如何在Matlab提示中添加日期或时间戳?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此问题已被标记为另一个问题的重复项询问的可能性 在提示中显示当前系统主机名.该问题的接受的答案成功使用了相同的答案自定义提示, 称为 setPrompt(),对这个问题做出可接受的答案(见下文).

This question has been marked as a duplicate of another question asking about the possibility of displaying the current system hostname in the prompt. The accepted answer to that question successfully uses the same custom prompt, called setPrompt(), as does the accepted answer to this question (see below).

但是请注意:该问题并未提及 日期/时间戳,答案也没有给出详细的分步说明 指示.下面的答案可以同时做这两种事情,或者,或者 可能并非如此,因此这是最适合您的答案.

Please note however: that question does not talk about date/timestamps, nor does the answer give detailed step-for-step instructions. The answer below does both of those things and might, or might not, therefore be the best-suited answer for you.

了解何时(例如"11:32 pm")已执行Matlab命令可能会很有用.我一直在寻找在Matlab提示中显示日期/时间戳的可能性.我正在Windows 10上使用Matlab R2017b.

It can be useful to know when (e.g. "11:32 pm") a Matlab command has been executed. I have been looking for the possibility to show a date/timestamp in the Matlab prompt. I am using Matlab R2017b on Windows 10.

有可能吗,如果可以的话,实施这种提示的逐步说明是什么?

Is that possible, and if so, what are the step-for-step instructions for implementing such a prompt?

最好我希望它看起来像以下内容:

Preferably I want it to look like the following:

[13:45:57] >> 1
ans =
     1
[13:45:58] >>

注意:事实证明,确实有可能检查答案(手写).

Note: It turns out that it is indeed possible, check the answer (self-written).

推荐答案

从R2017b版本开始,可以使用以下命令显示命令执行时间戳 setPrompt , 来自Matlab文件交换的自定义命令提示符(请参见下面的说明).

As of the R2017b release, it is possible to display command execution timestamps using setPrompt, a custom command prompt from the Matlab File Exchange (see instructions below).

有关代码的技术说明,请参见 作者的 原始博客 发布 关于setPrompt.

For a technical explanation of the code, see the author's original blog post about setPrompt.


配置自定义提示

配置自定义提示很简单,只需几分钟.


Configuring a custom prompt

Configuring a custom prompt is easy and takes only a few minutes.

  • 下载setPrompt.m并将其提取到您的Matlab 路径中(使用userpath命令找到它).
  • 如果要永久设置提示,可以在startup.m文件中拨打setPrompt()的电话.
  • 如果尚未配置启动文件,只需转到Matlab命令行并执行:

  • Download and extract setPrompt.m into your Matlab path (find it with the userpath command).
  • If you want to set the prompt permanently, you can put a call to setPrompt() in your startup.m file.
  • If you haven't configured your startup file, simply go to the Matlab command line and do:

  1. userpath

cd <YOUR_USERPATH>,(通常是C:\Users\<USER>\Documents\MATLAB).

例如,您可以在启动文件中放入setPrompt('<timestamp> '),以获得持续更新的日期/时间戳提示.要恢复默认提示,请调用不带参数的setPrompt.

As an example, you can put setPrompt('<timestamp> ') in your startup file to get a continuously updated date/timestamp prompt. To get back the default prompt, call setPrompt without arguments.

>> setPrompt('<timestamp> ')
<06-Feb-2018 01:00:51> 
<06-Feb-2018 01:00:53> setPrompt()
>>


要完全得到我想要的东西,我使用了setPrompt('[''['',datestr(now, ''HH:MM:SS''), ''] >> '']')

>>
>> setPrompt('[''['',datestr(now, ''HH:MM:SS''), ''] >> '']')
[13:45:57] >>
[13:45:57] >> 1

ans =

     1

[13:45:58] >>

这篇关于如何在Matlab提示中添加日期或时间戳?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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