简体   繁体   English

将Uitable的数据导出到Matlab中的电子表格Excel中

[英]Export uitable's data to a spreadsheet Excel in Matlab

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. 我设计了一个GUI,它有一个uitable和一个按钮,当按下时,它允许将uitable的数据导出到Excel电子表格。 My problem is that I want to add the uitable's headers to the matrix Select which has the numeric values. 我的问题是我想将uitable的标题添加到矩阵中选择哪个具有数值。 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

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]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM