フィルターのクリア

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 Center および File ExchangeString Parsing についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by