MATLAB Answers

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

조회 수: 1(최근 30일)
JP
JP 19 Nov 2019
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

  댓글 수: 0

로그인 to comment.

답변 수 (1)

Fangjun Jiang
Fangjun Jiang 19 Nov 2019
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 19 Nov 2019
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 20 Nov 2019
for k = 1:length(myFiles)
baseFileName = myFiles(k).name;
fullFileName = fullfile(myDir, baseFileName);
[~,MatFile]=fileparts(baseFileName);
I = xlsread(fullFileName);
save(MatFile,'I')
end

로그인 to comment.

이 질문에 답변하려면 로그인을(를) 수행하십시오.

태그


Translated by