- Initialize Structures: Create empty cell arrays for "DataSource", "LabelDefinitions", "LabelData".
- Load and Append: Use a loop to load each MAT file one by one. For each file, extract "DataSource", "LabelDefinitions", "LabelData" and append these to the corresponding cell arrays.
- Concatenate: Ensure that you concatenate along the correct dimension (e.g., rows for 2D matrices) to avoid creating multi-dimensional arrays.
- Save New File: After processing all files, save the final structures or arrays into a new MAT file.
How can I merge multiple LiDAR data annotation .mat files into a single file while maintaining consistent variables and appending data sequentially?
3 次查看(过去 30 天)
显示 更早的评论
I am working on LiDAR Labeller in MATLAB. So I have LiDAR data in nearly 1000 files .pcd (Point Cloud Data) format. So,without labelling 1000 pcd at a go, The pcd files were labeled by taking 50 .pcd files at a time and after labeling the labels are saved as .mat files i.e (1-50) as label_1.mat (51-100) as label_2.mat so on...
So as for training the data I need to merge all the .mat files in to one .mat file. The variables of all the files are same (DataSource, LabelDefinations,LabelData). So how to append the multiple .mat into single file while maintaining consistent variables and appending data sequentially? When I tried to append all .mat files Its actually appending in array format. In the below image, two .mat files are tried to append but in output file It is appended in array format. So, how can the appending done where the data in individual variable should be appended to the previous variable
.
0 个评论
回答(1 个)
Sai Pavan
2024-5-28
Hello Vishnu,
I understand that you want to merge multiple ".mat" files of LiDAR data into a single file while maintaining consistent variables and appending data sequentially. Please refer to the below workflow to perform this task:
Please refer to the below code snippet that demonstrates the workflow:
% Initialize empty cell arrays
allDataSources = {};
allLabelDefs = {};
allLabelData = {};
% Loop through each .mat file
for i = 1:numFiles
data = load(sprintf('label_%d.mat', i)); % Load the .mat file
% Append data to cell arrays
allDataSources = [allDataSources; data.DataSource];
allLabelDefs = [allLabelDefs; data.LabelDefinitions];
allLabelData = [allLabelData; data.LabelData];
end
% Save the concatenated data into a new .mat file
save('mergedData.mat', 'allDataSources', 'allLabelDefs', 'allLabelData');
Please refer to this documentation to learn more about "sprintf" function: https://www.mathworks.com/help/matlab/ref/sprintf.html
Hope it helps!
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Labeling, Segmentation, and Detection 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!