matlab輸出資料為excel檔案

sljwy發表於2020-12-28

例一:

第一行為標題,下面各列為其對應的資料。程式碼如下:

clear,clc
data = rand(5);
ht = {'需求','利用率','演算法編號','總數','週轉率'};
data = [ht;num2cell(data)];
xlswrite('data.xls',data);

例二:

pathout = 'E:\MS_DPP\Output\W_xyw.xlsx';
Title = {'X(m)', 'Y(m)', 'W'};
xlswrite(pathout,Title,1,'A1');
xlswrite(pathout,W_xyw,1,'A2');

結果:

例三:

function status = Out_Cords(filename,data)
switch class(data)
    case 'double'
        status = xlswrite(filename,data,1,'A1');
    case 'struct'
        fld_name = fieldnames(data);
        fld_num = size(fld_name,1);
        for i=1:fld_num
            subfld = fld_name{i,1};
            status = xlswrite(filename,data.(sprintf('%c',subfld)),i,'A1');
        end
end

結果:

case 'double' :

case 'strcut':

相關文章