2012-12-11 59 views
2

我想從日曆中獲取兩個日期。 MATLAB函數的是通過鼠標點擊獲取日期,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'}); 

,但如何讓用戶通過點擊這兩個日期。

回答

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

相關問題