Convert .mat files to csv file

17 visualizaciones (últimos 30 días)
Manisha Dunuarachchi
Manisha Dunuarachchi el 10 de En. de 2022
Editada: Manisha Dunuarachchi el 10 de En. de 2022
Hey,
I want to convert my mat-files to CSV. I have around 30 mat-files stored in the same folder. I'm going to process each .mat files using the below code and then save the output in csv format. All files have the same format and they are time series data.
T = datetime(datenum,'ConvertFrom','datenum','Format','yyyy-MM-dd HH:mm:ss.SSS');
u = timetable(T, axis1, axis2, axis3, 'VariableNames', {'a_xg', 'a_yg', 'a_zg'});
u.Properties.DimensionNames = {serial_number, 'Variables'};
TT = retime(u,'regular','mean','TimeStep',seconds(0.5));
writetimetable(TT,'e-2009RAW.csv');
I want to convert all .mat files in this folder to seperate CSV-files using a loop.
How am I supposed to write a loop to convert the .mat file into CSV using MATLAB?

Respuesta aceptada

KSSV
KSSV el 10 de En. de 2022
matFiles = dir('*.mat');
N = length(matFiles) ;
for i = 1:N
thisFile = matFiles(i).name ;
load(thisFile) ;
% Do what you want Let T be the date you made
[filepath,name,ext] = fileparts(thisFile) ;
writetable(T,[name,'.csv']) ;
end
  1 comentario
Manisha Dunuarachchi
Manisha Dunuarachchi el 10 de En. de 2022
Editada: Manisha Dunuarachchi el 10 de En. de 2022
This works fine with my code. Thanks

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Workspace Variables and MAT Files en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by