用于 GUI 的 MATLAB 日期选择弹出日历

发布于 2024-08-28 19:50:39 字数 459 浏览 6 评论 0原文

有谁知道在 MATLAB gui 中显示弹出日期选择日历的方法吗?我知道金融工具箱有一个uicalendar功能,但不幸的是我没有那个工具箱。

我有一种预感,我将不得不使用一些 Java 或其他语言来完成这个任务,但我对此一无所知。

我正在寻找与此类似的东西: 替代文本
(来源:welie.com

在用户选择日期后将返回日期字符串。

Does anyone know of a method to display a popup date selection calendar in a MATLAB gui? I know the financial toolbox has a uicalendar function, but unfortunately I don't have that toolbox.

I have a hunch I'm going to have to use some Java or some other language for this one, which I know nothing about.

I'm looking for something similar to this:
alt text
(source: welie.com)

which would return a date string after the user selects the date.

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

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

发布评论

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

评论(3

逆夏时光 2024-09-04 19:50:39

这里有两种方法可以在 Matlab 中为您提供具有专业外观的日历组件,而无需太多编程工作:

  1. 使用 Java 日历组件(例如,这些这些)。下载相关的 Java 类或 Jar 文件后,将其添加到静态 Java 类路径(使用 Matlab 命令提示符中的 edit('classpath.txt') 命令)。最后,使用内置的javacomponent函数将组件放置在Matlab图形窗口中。

  2. 如果您使用的是 Windows 操作系统,则可以嵌入任何可用的 Active-X 日历控件。使用内置的 actxcontrolselect 函数选择您最喜欢的日历控件(例如,Microsoft Office 的“日历控件 11.0”- MSCAL.Calendar.7 - 会自动安装Office 2003;或“Microsoft 日期和时间选择器控件 6.0”- MSComCtl2.DTPicker.2,或...)。然后使用actxcontrol函数将组件放置在Matlab图形窗口中。

  3. Matlab 有一些非常有用的内置日历(日期选择)控件 - 我发布了 an今天关于它们的文章

Here are two approaches that would give you a professional-looking calendar component in Matlab without too much programming work:

  1. Use a Java calendar component (for example, one of these or these). Once you download the relevant Java class or Jar-file, add it to your static Java classpath (use the edit('classpath.txt') command from the Matlab Command Prompt). Finally, use the built-in javacomponent function to place the component in your Matlab figure window.

  2. If you are using a Windows OS, you can embed any Active-X calendar control that is available. Use the built-in actxcontrolselect function to choose your favorite calendar control (for example, Microsoft Office's "Calendar Control 11.0" - MSCAL.Calendar.7 - which is automatically installed with Office 2003; or "Microsoft Date and Time Picker Control 6.0" - MSComCtl2.DTPicker.2, or ...). Then use the actxcontrol function to place the component in your Matlab figure window.

  3. Matlab has some pretty useful built-in calendar (date-selection) controls - I posted an article about them today

楠木可依 2024-09-04 19:50:39

不幸的是,我没有太多时间来获得更完整的答案,但我会尝试使用 uitable 创建一个表并定义 CellSelectionCallback 来获取日期。

这里有一些可以帮助您入门的信息:

dates = calendar;
dates(~any(dates,2),:) = [];
fh = figure;
uh = uitable('parent',fh,'data',dates,'ColumnWidth',repmat({20},1,7),...
             'ColumnName',{'S','M','T','W','T','F','S'});

I don't have much time for a more complete answer, unfortunately, but I'd try uitable to create a table and to define the CellSelectionCallback to get the date.

Here's a bit to get you started:

dates = calendar;
dates(~any(dates,2),:) = [];
fh = figure;
uh = uitable('parent',fh,'data',dates,'ColumnWidth',repmat({20},1,7),...
             'ColumnName',{'S','M','T','W','T','F','S'});
梦与时光遇 2024-09-04 19:50:39

我从 calendar() 函数 开始它输出一个包含任意月份日历的矩阵。我假设您可以将其与用户可点击的界面结合起来以检索特定日期?

下面的代码确实很难看,但可以帮助你开始......

 WINDOW_WIDTH = 300;
 WINDOW_HEIGHT = 200;
f= figure('Position',[300 300 WINDOW_WIDTH WINDOW_HEIGHT]);

 NB_ROWS = 6;
 NB_COLS = 7;
 width = round(WINDOW_WIDTH/NB_COLS);
 height = round(WINDOW_HEIGHT/NB_ROWS);
 buttons = nan(NB_ROWS,NB_COLS);
 dates = calendar();

 for row = 1:NB_ROWS
    for col = 1:NB_COLS
       if dates(row,col) == 0
          mydate = '';
       else
          mydate = sprintf('%i', dates(row,col));
       end
       buttons(row,col) = uicontrol('Style', 'PushButton', ...
          'String', mydate, ...
          'Position', [(col-1)*width (NB_ROWS - row)*height width height]);
    end
 end

I'd start with the calendar() function which outputs a matrix containing the calendar for any month. I assume you could combine this with a user-clickable interface to retrieve a specific date?

The following code is really ugly, but could help you get started...

 WINDOW_WIDTH = 300;
 WINDOW_HEIGHT = 200;
f= figure('Position',[300 300 WINDOW_WIDTH WINDOW_HEIGHT]);

 NB_ROWS = 6;
 NB_COLS = 7;
 width = round(WINDOW_WIDTH/NB_COLS);
 height = round(WINDOW_HEIGHT/NB_ROWS);
 buttons = nan(NB_ROWS,NB_COLS);
 dates = calendar();

 for row = 1:NB_ROWS
    for col = 1:NB_COLS
       if dates(row,col) == 0
          mydate = '';
       else
          mydate = sprintf('%i', dates(row,col));
       end
       buttons(row,col) = uicontrol('Style', 'PushButton', ...
          'String', mydate, ...
          'Position', [(col-1)*width (NB_ROWS - row)*height width height]);
    end
 end
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文