Converting the label info in .txt file to .mat file

4 views (last 30 days)
i have label info of lidar data in txt format and there are more than 2500 files i want to convert to .mat file for to be able to use it in matlab for object detection using this Lidar Object Detection Using Complex-YOLO v4 Network.
So please help me with this.
  2 Comments
cui,xingxing
cui,xingxing on 9 Apr 2024
Can you briefly share a txt to mat file that best describes the problem?
gaurav
gaurav on 9 Apr 2024
I have a lidar dataset whoose labels are in txt format and I want to perform perform object detection using complex yolo documentation which need the labels in .mat format but i am not able to do so.
Is it possible to convert these txt files into a single mat file.
Or do I need to make changes in the code so it will be able to take txt file as input for label info if so can you provide me with any example of same

Sign in to comment.

Answers (1)

Chandrika
Chandrika on 19 Jul 2024
Hello Gaurav,
For converting a set of ".txt" files containing label information of your lidar data into ".mat" format, you may read the ".txt" files using the "readmatrix" function and then save the data into ".mat" format. For your reference on the same, I am attaching below a sample code snippet:
% Define the folders containing the ".txt" files and ".mat" files
txtFolder = 'path_to_folder_having_txt_files';
matFolder = 'path_to_folder_to_save_mat_files';
% Create a destination folder to save the ".mat" files
if ~exist(matFolder, 'dir')
mkdir(matFolder);
end
txtFiles = dir(fullfile(txtFolder, '*.txt'));
% Loop through each TXT file, read the data, and save it as a MAT file
for i = 1:length(txtFiles)
txtFilePath = fullfile(txtFolder, txtFiles(i).name);
% Read the data from the ".txt" file using "readmatrix" funcion
labelData = readmatrix(txtFilePath);
[~, name, ~] = fileparts(txtFiles(i).name);
matFilePath = fullfile(matFolder, [name, '.mat']);
% Save the label data into a ".mat" file
save(matFilePath, 'labelData');
end
For more information on the "readmatrix" and "save" functions, you may refer the following MathWorks documentation links:
I hope you find the suggested workaround useful!
Regards,
Chandrika

Tags

Products


Release

R2024a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!