MATLAB-读取多个* .log文件,计算并另存为。* txt文件到新文件夹中

时间:2018-11-22 10:21:04

标签: matlab file

我采取了不同的措施,并将其保存为* .log文件,然后对其进行计算并另存为。* txt。

%Filtering log files 
l = dir('*.log');

%Array size detection
[rows cols] = size(l);

%Choose a last file
file_name =  strcat(strcat(l(rows).folder,'/'),l(rows).name)

%Reading log last file 
fileread = fopen(file_name);

%Convert to float
times = fread(fileread,'float32');

%Filtering times and set to 0 small values
times(times<1e-8)=0;

%Set right times values
times_s = times * 1.0e-06;

%Solve full rotation speed (Hz)
motorspeed_full = 1./(2.*times_s)

%Filtering inf values and set to 0
motorspeed_full(motorspeed_full>1e+10)=0;

%Solve half rotation speed (Hz)
motorspeed_half = 1./(times_s);

A = '.txt';

[filepath,name,ext] = fileparts(file_name);

Xfilename = cat(2,name,A);

dlmwrite(Xfilename,motorspeed_full,'precision','%.3f');

因此,可以选择最后一个文件,对其进行计算并将其转换为。* txt。所以现在,我必须在每次测量后进行计算。

enter image description here

我的目标是:

  • 先进行1 ... n次测量(1 ... n-* .log和wav)
  • 计算并保存1 ... n * .log文件到* .txt文件(见图)
  • 使用文件名(例如20181120_125713)创建文件夹,并将file_name.txt和file_name.wav插入此文件夹结构Aim

问题:

  • 如何使用dlmwrite将所有* .log文件转换为* .txt文件?
  • 如何创建一个具有file_name的新文件夹

    mkdir(name);

对于所有文件?

  • 如何将同名文件移动到同名文件夹?文件夹名称每次都会更改,因此我无法使用

    移动文件源目标

    非常感谢您的帮助:*)

1 个答案:

答案 0 :(得分:0)

这是我的解决方案。也许可以帮助某人:

(x*y)%z == ((x%z) * (y%z)) % z