how to save lists into mat-file while keeping their original name?

1 次查看(过去 30 天)
Hi,
I am currently trying to read in a couple of xlsx-files (basically lists, that consist of one column of 1 to 4 numeric values) into a mat-file.
My problem is that the code below only saves one xlsx-file - named 'I' - into the mat-file.
I want to save every xlsx-file within the folder into the mat-file under their original names (=baseFileName).
Is there any way to do this?
myDir = uigetdir('*.*', 'Please select Input Folder');
myFiles = dir(fullfile(myDir,'*.xlsx'));
for k = 1:length(myFiles)
baseFileName = myFiles(k).name;
fullFileName = fullfile(myDir, baseFileName);
I = xlsread(fullFileName);
save('v1.mat','I', '-append')
end

回答(1 个)

Fangjun Jiang
Fangjun Jiang 2019-11-19
for k = 1:length(myFiles)
baseFileName = myFiles(k).name;
fullFileName = fullfile(myDir, baseFileName);
I{k} = xlsread(fullFileName);
end
save('v1.mat','I')
  2 个评论
JP
JP 2019-11-19
thank you for your reply, unfortunately this does not solve my problem.
Firstly, there is still only one file saved into the v1.mat file and it is still called 'I'.
Also, and I should have prevised this before, 'I' is now a matrix (shown as '{}'), but the lists are supposed to be read in and saved as vectors, I believe.
Fangjun Jiang
Fangjun Jiang 2019-11-20
for k = 1:length(myFiles)
baseFileName = myFiles(k).name;
fullFileName = fullfile(myDir, baseFileName);
[~,MatFile]=fileparts(baseFileName);
I = xlsread(fullFileName);
save(MatFile,'I')
end

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Scripts 的更多信息

标签

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by