I have data stored in the .tdms format, gathering the data of many sensors, measured every second, every day. A new tdms file is created every day, and stored in a folder per month. Using the convertTDMS function, I have converted these tdms files to mat files.
我有存储在.tdms格式的数据,收集了许多传感器的数据,每一秒都测量一次。每天创建一个新的tdms文件,并将其存储在每个月的文件夹中。使用convertTDMS函数,我将这些tdms文件转换为mat文件。
As there are some errors in some of the measurements(e.g. negative values which can not physically occur), I have performed some corrections by loading one mat file at a time, do the calculations and then save the data into the original .mat file.
因为在一些测量中有一些错误。我通过一次加载一个mat文件进行了一些修正,进行计算,然后将数据保存到原始的.mat文件中。
However, when I try to do what I described above in a loop (so: load .mat in folder, do calculations on one mat file (or channel therein), save mat file, repeat until all files in the folder have been done), I end up running into trouble with the limitations of the save function: so far I save all variables (or am unable to save) in the workspace when using the code below.
然而,当我试着做我上面描述的在一个循环中(如此:负载.mat文件夹,计算一个垫子上文件(或频道在其中),保存垫文件,重复,直到所有文件在文件夹已经完成),我最终陷入困境的保存函数的局限性:到目前为止我保存所有变量在工作区中(或者是无法保存)当使用以下代码。
for k = 1:nFiles
w{k,1} = load(wMAT{k,1});
len = length(w{k,1}.(x).(y).(z));
pos = find(w{k,1}.(x).(y).(z)(1,len).(y)<0); %Wind speed must be >0 m/s
for n = 1:length(pos)
w{k,1}.(x).(y).(z)(1,len).(y)(pos(n)) = mean([w{k,1}.(x).(y).(z)(1,len).(y)(pos(n)+1),...
w{k,1}.(x).(y).(z)(1,len).(y)(pos(n)-1)],2);
end
save( name{k,1});
%save(wMAT{k,1},w{k,1}.(x),w{k,1}.ConvertVer,w{k,1}.ChanNames);
end
A bit of background information: the file names are stored in a cell array wMAT of length nFiles in the folder. Each cell in the cell array wMAT stores the fullfile path to the mat files. The data of the files is loaded and saved into the cell array w, also of length nFiles. Each cell in "w" has all the data stored from the tdms to mat conversion, in the format described in the convertTDMS description. This means: to get at the actual data, I need to go from the
一些背景信息:文件名称存储在文件夹中长度为nFiles的单元数组wMAT中。单元格数组wMAT中的每个单元都将fullfile路径存储到mat文件。文件的数据被加载并保存到单元数组w中,也就是长度nFiles。“w”中的每个单元格都有从tdms到mat转换的所有数据,以convertTDMS描述中描述的格式。这意味着:为了得到实际的数据,我需要从。
- cell in the cell array w{k,1} (my addition)
- 单元格中的单元格w{k,1}(我的加法)
- to the struct array "ConvertedData" (Structure of all of the data objects - part of convertTDMS)
- 对于struct数组“ConvertedData”(所有数据对象的结构——convertTDMS的一部分)
- to the struct array below called "Data" (convertTDMS)
- 下面的struct数组称为“数据”(convertTDMS)
- to the struct array below called "MeasuredData" (convertTDMS) -> at this level, I can access the channels which store the data.
- 对于下面的struct数组,称为“度量数据”(convertTDMS) ->在这个级别,我可以访问存储数据的通道。
- to finally access/manipulate the values stored, I have to select a channel, e.g. (1,len), and then go via the struct array to the actual values (="Data"). (convertTDMS) In Matlab format, this looks like "w{1, 1}.ConvertedData.Data.MeasuredData(1, len).Data(1:end)" or "w{1, 1}.ConvertedData.Data.MeasuredData(1, len).Data".
- 为了最终访问/操作存储的值,我必须选择一个通道,例如(1,len),然后经过struct数组到实际值(="Data")。在Matlab格式下,这看起来像“w{1, 1}. converteddata . data”。测量数据(1,len). data (1:end)"或"w{1, 1}. converteddata . data。len MeasuredData(1). data”。
To make typing easier, I took
为了让打字更容易,我选了。
x = 'ConvertedData';
y = 'Data';
z = 'MeasuredData';
allowing me to write instead:
让我改为:
w{k,1}.(x).(y).(z)(1,len).(y)
using the dot notation.
使用点符号。
My goal/question: I want to load the values stored in a .mat file from the original .tdms files in a loop to a cell array (or if I can do better than a cell array: please tell me), do the necessary calculations, and then save each 'corrected' .mat file using the original name.
我的目标/问题:我想要加载的值存储在一个从原始.tdms .mat文件文件在一个循环单元阵列(或者如果我可以做得更好一个单元阵列:请告诉我),做了必要的计算,然后保存每个“纠正”.mat文件使用原来的名称。
So far, I have gotten a multitude of errors from trying a variety of solutions, going from "getfieldnames", trying to pass the name of the (dynamically changing) variable(s), etc.
到目前为止,我已经从尝试各种各样的解决方案中得到了大量的错误,从“getfieldnames”,试图传递(动态变化的)变量的名称,等等。
Similar questions which have helped me get in the right direction include Saving matlab files with a name having a variable input, Dynamically Assign Variables in Matlab and http://www.mathworks.com/matlabcentral/answers/4042-load-files-containing-part-of-a-string-in-the-file-name-and-the-load-that-file , yet the result is that I am still no closer than doing manual labour in this case.
类似的问题也帮助我找到了正确的方向,其中包括保存matlab文件,名字有变量输入,在matlab中动态地分配变量,以及http://www.mathworks.com/matlabcentral/answers/4042-load-files- in- in- file-name-and- load- at-file,但结果是,在这种情况下,我仍然没有做手工劳动。
Any help would be appreciated.
如有任何帮助,我们将不胜感激。
1 个解决方案
#1
0
If I understand your ultimate goal correctly, I think you're pretty much there. I think you're trying to process your .mat files and that the loading of all of the files into a cell array is not a requirement, but just part of your solution? Assuming this is the case, you could just load the data from one file, process it, save it and then repeat. This way you only ever have one file loaded at a time and shouldn't hit any limits.
如果我正确地理解了你的最终目标,我认为你在这方面是相当出色的。我认为您正在尝试处理您的.mat文件,并且将所有文件加载到一个单元数组中不是一个要求,而是您的解决方案的一部分?假设情况是这样,您可以只从一个文件加载数据,处理它,保存它,然后重复。这样,每次只加载一个文件,并且不应该受到任何限制。
Edit
编辑
You could certainly make a function out of your code and then call that in a loop, passing in the file name to modify. Personally I'd probably do that as I think it's neater solution. If you don't want to do that though, you could just replace w{k,1}
with w
then each time you load a file w
would be overwritten. If you wanted to explicitly clear variables you can use the clear
command with a space separated list of variables e.g. clear w len pos
, but I don't think that this is necessary.
当然,您可以从代码中创建一个函数,然后在循环中调用该函数,并将其传递到文件名进行修改。就我个人而言,我可能会这么做,因为我认为这是一个更简洁的解决方案。如果你不想这样做,你可以替换w{k,1}然后每次你加载一个文件w就会被覆盖。如果您想要显式地清除变量,您可以使用clear命令和分隔的变量列表,例如clear w len pos,但我不认为这是必要的。
#1
0
If I understand your ultimate goal correctly, I think you're pretty much there. I think you're trying to process your .mat files and that the loading of all of the files into a cell array is not a requirement, but just part of your solution? Assuming this is the case, you could just load the data from one file, process it, save it and then repeat. This way you only ever have one file loaded at a time and shouldn't hit any limits.
如果我正确地理解了你的最终目标,我认为你在这方面是相当出色的。我认为您正在尝试处理您的.mat文件,并且将所有文件加载到一个单元数组中不是一个要求,而是您的解决方案的一部分?假设情况是这样,您可以只从一个文件加载数据,处理它,保存它,然后重复。这样,每次只加载一个文件,并且不应该受到任何限制。
Edit
编辑
You could certainly make a function out of your code and then call that in a loop, passing in the file name to modify. Personally I'd probably do that as I think it's neater solution. If you don't want to do that though, you could just replace w{k,1}
with w
then each time you load a file w
would be overwritten. If you wanted to explicitly clear variables you can use the clear
command with a space separated list of variables e.g. clear w len pos
, but I don't think that this is necessary.
当然,您可以从代码中创建一个函数,然后在循环中调用该函数,并将其传递到文件名进行修改。就我个人而言,我可能会这么做,因为我认为这是一个更简洁的解决方案。如果你不想这样做,你可以替换w{k,1}然后每次你加载一个文件w就会被覆盖。如果您想要显式地清除变量,您可以使用clear命令和分隔的变量列表,例如clear w len pos,但我不认为这是必要的。