2011-11-09 173 views
1

我設計了一個具有可用鍵和按鈕的GUI,當它被按下時,它允許將可用表格的數據導出到Excel電子表格。我的問題是,我想將可用的標題添加到矩陣選擇具有數字值。這個矩陣由按鈕回調使用,如圖所示:將可導出數據導出到電子表格Excel中的Excel

htable = uitable(...); 
... 
SelecY = get(htable,'Data'); 

回調按鈕的

function hExpExcelCallback(src,evt) 
     FileName = uiputfile('*.xls','Save as'); 
     xlswrite(FileName,SelecY), 
    end 
+0

@ Amro:非常感謝您的編輯。 – julian

回答

4

實施例:

headers = cellstr(num2str((1:5)','header %d'))'; 
data = rand(10,5); 

A = [headers ; num2cell(data)]; 
xlswrite('file.xls',A) 

內容:

>> A 
A = 
    'header 1' 'header 2' 'header 3' 'header 4' 'header 5' 
    [ 0.34998] [ 0.28584] [ 0.12991] [ 0.60198] [ 0.82582] 
    [ 0.1966] [ 0.7572] [ 0.56882] [ 0.26297] [ 0.53834] 
    [ 0.25108] [ 0.75373] [ 0.46939] [ 0.65408] [ 0.99613] 
    [ 0.61604] [ 0.38045] [0.011902] [ 0.68921] [ 0.078176] 
    [ 0.47329] [ 0.56782] [ 0.33712] [ 0.74815] [ 0.44268] 
    [ 0.35166] [0.075854] [ 0.16218] [ 0.45054] [ 0.10665] 
    [ 0.83083] [ 0.05395] [ 0.79428] [0.083821] [ 0.9619] 
    [ 0.58526] [ 0.5308] [ 0.31122] [ 0.22898] [0.0046342] 
    [ 0.54972] [ 0.77917] [ 0.52853] [ 0.91334] [ 0.77491] 
    [ 0.91719] [ 0.93401] [ 0.16565] [ 0.15238] [ 0.8173] 
+0

非常感謝您的回答。 – julian