通过鼠标点击获取日期,matlab

通过鼠标点击获取日期,matlab,matlab,matlab-uitable,Matlab,Matlab Uitable,我想从日历中得到两个日期。 matlab函数是 c = calendar 或 但是如何让用户点击这两个日期。创建回调函数: 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

我想从日历中得到两个日期。 matlab函数是

c = calendar


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

创建回调函数:

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\u select\u callback)

按下时,cell_select_callback将打印单击的坐标和日期,例如:
cell\u select\u callback():于2012年12月4日点击[23]

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