Converting .mat to .txt which also contains cell arrays.

조회 수: 2 (최근 30일)
Lab
Lab 2023년 10월 9일
편집: prabhat kumar sharma 2023년 10월 26일
I am using the Lidar labeler app from the lidar toolbox in MATLAB. When i annotate the pcds and save them, they are saved in .mat files. We know, when there is more than 1 object in a frame, they are stored in cell arrays. I have 9 classes in my annotation and i want to store these label data frame wise and class wise in a text file. How do i do it? For your reference, the structure of the Label data is attached.
I have tried accessing the cell arrays but failed continuously. Would really appreciate your help in this regard.
Thank you in advance!
  댓글 수: 4
Lab
Lab 2023년 10월 10일
I would like to create seperate text files for each annotation, yes.
A JSON file is also something i want to work with soon.
Rik
Rik 2023년 10월 10일
What does jsonencode do with this data?

댓글을 달려면 로그인하십시오.

답변 (1개)

prabhat kumar sharma
prabhat kumar sharma 2023년 10월 26일
편집: prabhat kumar sharma 2023년 10월 26일
Hi Lab,
I understand that you are facing issue with storing data label wise and class wise in a text file.
To store the label data frame-wise and class-wise from the Lidar Labeler app in MATLAB, you can extract the relevant information from the saved MAT files and write it to a text file. Here's a step-by-step approach to help you accomplish this:
1. Load the label data from the .mat file:
load('label_data.mat'); % Replace 'label_data.mat' with the path to your label data file
2. Access the necessary fields in the label data structure:
frameData = label_data.frameAnnotations;
3. Iterate through each frame and extract the class-wise labels:
numFrames = numel(frameData);
numClasses = numel(label_data.labelDefinitions);
% Create a cell array to store the labels for each frame and class
labels = cell(numFrames, numClasses);
for i = 1:numFrames
for j = 1:numClasses
% Extract the labels for each class in the current frame
labels{i, j} = frameData(i).objectAnnotations(j).classification;
end
end
4. Write the label data to a text file:
filename = 'label_data.txt'; % Specify the filename for the text file
fid = fopen(filename, 'w'); % Open the file for writing
for i = 1:numFrames
fprintf(fid, 'Frame %d:\n', i);
for j = 1:numClasses
fprintf(fid, 'Class %d: ', j);
% Write the labels for each class in the current frame
if isempty(labels{i, j})
fprintf(fid, 'No label\n');
else
fprintf(fid, '%s\n', labels{i, j});
end
end
fprintf(fid, '\n');
end
fclose(fid); % Close the file
You can use the above code for reference for your MAT file and class and frame label.
After executing the above code, you will have a text file (`label_data.txt`) containing the label data frame-wise and class-wise. Each frame will be labelled with the corresponding class information. If there is no label for a specific class in a frame, it will be indicated as "No label" in the text file.
I hope it helps!

카테고리

Help CenterFile Exchange에서 Labeling, Segmentation, and Detection에 대해 자세히 알아보기

제품


릴리스

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by