search and find specific measured data name rows in structure and save corresponding data
1 次查看(过去 30 天)
显示 更早的评论
I'm creating code to pull TDMS data into Matlab so that I can examine and track test results.
Currently I'm able to import several files. These files are then thrown into a structure together. The result is shown:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/794054/image.jpeg)
In order to limit the scope of my question, I'll try to be brief: right now I import 5 or so files that sometimes have the same layout (eg. each row within LT(1).Data.MeasuredData matches the row within LT(2).Data.MeasuredData), however there are times when this is not the case. So I cannot simply concatenate the data from row 8 in LT(1).Data.MeasuredData(8).Data with the data from LT(2).Data.MeasuredData(8).Data and call it Discharge pressure in order to plot... Instead I would need to figure out the data based on the "Name" within each LT(1:5), store it as a variable, then concatenate these variables in order to graph.
I would like to set up code that looks within each file [LT(1:5)], finds the name "Utempra 1/Ambient (F)" (also several other variables), stores the corresponding data as a vector that I can then combine to make a complete variable through concatenation.
0 个评论
回答(1 个)
Vatsal
2024-2-21
Hi,
In order to search and find specific measured data name rows in the structure and save corresponding data, you can loop through the structure array and check the "Name" field of each element within the "MeasuredData" array. When a match for the name "Utempra 1/Ambient (F)" (or any other specified variable names) is identified, the relevant data can be extracted and concatenated into a vector.
The following code snippet provides an example of how to perform this operation for the "Utempra 1/Ambient (F)" variable:
% Initialize an empty cell array to store the data
allData = {};
% Loop over all the LT structures
for i = 1:length(LT)
% Get the MeasuredData from the current LT structure
measuredData = LT(i).Data.MeasuredData;
% Loop over all the MeasuredData
for j = 1:length(measuredData)
% Check if the Name matches
if strcmp(measuredData(j).Name, 'Utempra 1/Ambient (F)')
% If it does, append the Data to the allData cell array
allData{end+1} = measuredData(j).Data;
end
end
end
% Now, allData is a cell array where each element is a vector of data
% from one of the LT structures. You can concatenate them into a single
% vector like this:
concatenatedData = vertcat(allData{:});
I hope this helps!
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Matrix Indexing 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!