matlab读取多个excel并输出

2025-11-05 04:36:48

1、适合的读取的excel数据格式

matlab读取多个excel并输出

2、matlab代码如下:

clear;

clc;

filePath=uigetdir({},'choose your filepath'); %获取excel文件存储目录

getFileName=ls(strcat(filePath,'\*.xl*'));  %获取所选目录下的文件名

fileName = cellstr(getFileName); %将string数组转为cell数组

  

if  isequal(getFileName,'')%防止选择空文件夹

   msgbox('no excel file in the path you selected');

else 

  

mkdir(strcat(filePath,'\output'));%新建输出文件夹

waiting=waitbar(0,'excuting...,please wait!');%进度条

for i=1: length(fileName)                                                  %foreach your files  

    [excelData,str] = xlsread(strcat(filePath,'\',fileName{i}));%读取excel

  xlswrite(strcat(filePath,'\output\output.xlsx'),str,strcat('Sheet',num2str(i)), 'A1');%将读取的工作表表头写入excel

    xlswrite(strcat(filePath,'\output\output.xlsx'),excelData,strcat('Sheet',num2str(i)), 'A2');%将读取的工作表数字写入excel

    

end

close(waiting)%关闭进度条

disp 'you can find output file there:'

outputPath = strcat(filePath,'\output\output.xlsx')

msgbox(strcat('finished,get output file in:',outputPath),'Success','Help');%prompt message

end

3、新建演示的excel文件

matlab读取多个excel并输出

4、运行代码,选择好存放Excel文件的文件夹

matlab读取多个excel并输出

5、选择好文件夹后开始计算

matlab读取多个excel并输出

matlab读取多个excel并输出

6、运行结束,输出结果

matlab读取多个excel并输出

matlab读取多个excel并输出

声明:本网站引用、摘录或转载内容仅供网站访问者交流或参考,不代表本站立场,如存在版权或非法内容,请联系站长删除,联系邮箱:site.kefu@qq.com。
猜你喜欢