MATLAB date selection popup calendar for gui

别来无恙 提交于 2019-12-19 19:03:13

问题


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:
(source: welie.com)

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


回答1:


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'});



回答2:


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




回答3:


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


来源:https://stackoverflow.com/questions/2655554/matlab-date-selection-popup-calendar-for-gui

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