Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MATLAB date selection popup calendar for gui

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.

like image 921
Doresoom Avatar asked Apr 16 '10 19:04

Doresoom


People also ask

What is dateTime picker?

The DateTimePicker control is used to allow the user to select a date and time, and to display that date and time in the specified format. The DateTimePicker control makes it easy to work with dates and times because it handles a lot of the data validation automatically.


3 Answers

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

like image 144
Yair Altman Avatar answered Nov 08 '22 07:11

Yair Altman


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'});
like image 41
Jonas Avatar answered Nov 08 '22 07:11

Jonas


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
like image 30
Kena Avatar answered Nov 08 '22 07:11

Kena