[英]create a .txt file that lists all files in directory, using Matlab on Windows
[英]Automating reading, treating and saving .txt files in a directory using Matlab
我有一個包含兩個文件夾的目錄:一個文件夾包含多個帶有多個.txt文件的子文件夾(文件夾1)。 第二個文件夾包含幾個.hjson文件(文件夾2)。
我想加載每個.txt和.hjson文件進行幾次計算(例如,速度,加速度,曲率),並保存在同一.txt文件中,並添加帶有標題的新聞列(例如,速度,加速度,曲率)。 到目前為止,我只有一個代碼可以加載.txt文件。
我的目標是使代碼能夠讀取,加載,計算並自動保存。 如果您有任何建議,請告訴我。
%% 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
您可以使用fprintf
寫入文件。 例如:
formatSpec="%9.5f %8.5f\n";
for i=1:n
fprintf(fid,formatSpec, var1(i),var2(i));
end
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.