Automatisation for reading, treating and saving .txt files in a directory folder.

조회 수: 2 (최근 30일)
Hello everybody,
I have a directory with two folders: one folder contain several subfolders with multiple .txt files (folder 1). The second folder contains several . hjson files (folder 2). I would like load each .txt and hjson files make a several calculation (e.g. velocity, acceleration...) and save a new .csv file in another directory folder in the PC with the same name of the .txt files but adding ‘done’ or ‘treated’. So far, have two code one to load .txt files and another that add the header and save but without changing the name automatically. My goal is to make a code that reads, loads, computes and save automatically in a different folder (). Please let me know if you have any suggestion about.
%% Read and load dir_to_search = 'C:\Programs\pedro\Test\';
txtpattern = fullfile(dir_to_search, '*.txt');
dinfo = dir(txtpattern);
for K = 1 : length(dinfo)
thisfilename = fullfile(dir_to_search, dinfo(K).name); %just the name
thisdata = load(thisfilename); %load just this file
End
%% %% Adding Headers to the Matrix
headers={'Timestamp','PosX','PosZ','PosY','RotX','RotY','RotZ','RPosX','RPosZ','RPosY','RRotX','RRotY','RRotZ','velocity','acceleration','curvature','distance','target_reached'};
fmt = repmat(',%.12g',1,size(data,2)); % pick numeric format to suit!
fmt = [fmt(2:end),'\n'];
[fid,msg] = fopen('output1.csv','wt');
assert(fid>=3,msg)
fprintf(fid,'%s',headers{1})
fprintf(fid,',%s',headers{2:end})
fprintf(fid,'\n')
fprintf(fid,fmt,data.')
fclose(fid);

답변 (0개)

카테고리

Help CenterFile Exchange에서 MATLAB Mobile에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by