MATLAB date selection popup calendar for gui

前端 未结 3 1379
长情又很酷
长情又很酷 2021-01-18 13:46

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 unfortunate

相关标签:
3条回答
  • 2021-01-18 14:10

    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'});
    
    0 讨论(0)
  • 2021-01-18 14:20

    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
    
    0 讨论(0)
  • 2021-01-18 14:26

    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

    0 讨论(0)
提交回复
热议问题