我想从日历中获取两个日期。 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'});
但是如何让用户点击这两个日期。
答案 0 :(得分: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