2

我想从日历中获取两个日期。matlab函数是

c = calendar

或者

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

但是如何让用户点击这两个日期。

4

1 回答 1

1

创建回调函数:

function cell_select_callback(h, ind)
    dates = get(h, 'data');
    d = dates(ind.Indices(1), ind.Indices(2));
    if d == 0
        return
    end
    dn = datenum(2012, 12, d); % you have to have year & month here
    fprintf('cell_select_callback(): click at [%d %d] on %s\n', ind.Indices(1), ind.Indices(2), datestr(dn));
return

并添加到 uitable() 参数中:uitable(..., 'CellSelectionCallback', @cell_select_callback).

按下时,cell_select_callback 将打印点击的坐标和日期,例如: cell_select_callback(): click at [2 3] on 04-Dec-2012

于 2012-12-11T16:43:28.927 回答