필터 지우기
필터 지우기

Convert all csv in a folder to .mat

조회 수: 19 (최근 30일)
Elise Barbeau
Elise Barbeau 2021년 2월 3일
댓글: Jan 2021년 2월 5일
I have several csv files in one folder and I want to convert them all to .mat format?
Is it possible to do that at once?

채택된 답변

Jan
Jan 2021년 2월 3일
편집: Jan 2021년 2월 4일
Folder = 'D:\YourFolder';
FileList = dir(fullfile(Folder, '*.csv'));
for iFile = 1:numel(FileList)
% [TYPO FIXED]: [name, ext] ==> [~, name, ext]
[~, name, ext] = fileparts(FileList(iFile).name);
data = readtable(fullfile(Folder, [name, ext]));
save(fullfile(Folder, [name, '.mat']), 'data');
end
  댓글 수: 10
Elise Barbeau
Elise Barbeau 2021년 2월 5일
yes I saw that too but to do it on all the files in my folder at once?
Jan
Jan 2021년 2월 5일
This suggestion does it during the creation already. Then you do not have to do it again. But the code looks similar to the one of my answer:
Folder = 'D:\YourFolder';
FileList = dir(fullfile(Folder, '*.mat'));
for iFile = 1:numel(FileList)
FileData = load(fullfile(Folder, FileList(iFile).name));
data = FileData.data;
data(1, :) = [];
save(fullfile(Folder, [name, '.mat']), 'data');
end

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 String Parsing에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by