matlab实现xlsx文件转mat文件
实验中常常需要将表格文件转换为mat文件进行处理,下面提供多sheet表格文件转mat文件的代码
%将xlsx文件转为mat文件,版本>R2019a
clear
fileName = 'test.xlsx'; %xlsx文件名
savePath = 'D:\MATLAB\'; %mat文件保存路径
saveName = 'test.mat'; %mat文件名
sheets = sheetnames(fileName); %xlsx文件各sheet名
matNames = ["trainData";"trainLabel";"testData";"testLabel"]; %mat文件各变量名
for i = 1:length(sheets)
matName = char(matNames(i));
eval(['m_',matName, '= readmatrix(fileName,"sheet",sheets(i));']);
end
save(strcat(savePath,saveName),'m_*');