Domanda

I have designed a GUI which has an uitable and a push button which, when is pressed, allows to export the uitable's data to an Excel spreadsheet. My problem is that I want to add the uitable's headers to the matrix Select which has the numeric values. This matrix is used by the pushbutton callback, as seen below:

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

Callback of the pushbutton

    function hExpExcelCallback(src,evt)
        FileName = uiputfile('*.xls','Save as');
        xlswrite(FileName,SelecY),
    end
È stato utile?

Soluzione

Example:

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

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

the content:

>> 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]
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top