1. 程式人生 > 實用技巧 >excel—write

excel—write

利用Matlab將資料寫入excel檔案中:

連結:https://ww2.mathworks.cn/help/matlab/ref/writetable.html

   

  函式:writeable;writeable;writematrix;xlswrite(不推薦)

  語法:

writeable
writeable
writematrix
writetable(T)
writetable(T,filename)
writetable(___,Name,Value)
writecell(C)
writecell(C,filename)
writecell(___,Name,Value)
writematrix(A)
writematrix(A,filename)
writematrix(___,Name,Value)

一、將表寫入到電子表格中特定的工作表和範圍

  writetable(T,'myData.xls','Sheet',1,'Range','B2:F6')

  注意:T的資料型別是cell

  matlab 資料轉換:

  • cell2mat:將cell轉換為mat的char型
  • str2num:將mat從char轉換為double型
  • cellstr:將char轉cell
  • num2str:將double轉char
  • num2cell:將double直接轉cell
%獲取資料夾下所有jpg檔案的名稱,然後寫入excel檔案

%獲取檔名稱
filepath = 'D:\Users\zhuyingdi\Desktop\表彰\*.jpg';
fileinfo = dir(filepath);%獲取檔案的所有資訊

len = length(fileinfo);
write_filename = '11.xls';

for i = 1:len
    T = fileinfo(i).name;
    C = cellstr(T);
    i1 = num2str(i);
    cell = strcat('A',i1);
    writecell(C,write_filename,
'Sheet',1,'Range',cell); end