Azzera filtri
Azzera filtri

How to merge rows of a table

8 visualizzazioni (ultimi 30 giorni)
Jiongyi Meng
Jiongyi Meng il 3 Mag 2022
Risposto: Rahul il 10 Set 2024 alle 11:13
I created the following table from the csv file when I created the deep learning training labels. The next step is to use the boxLabelDatastore function for processing. Before that, I can see the first column of the table, that is, the file name is repeated, which means that each training The data has multiple labels. How can I combine the lines with the same file name to achieve the effect of labeling one training data with multiple labels at the same time?

Risposte (1)

Rahul
Rahul il 10 Set 2024 alle 11:13
I understand that you wish to merge those rows of the table which contain the same filename along with their labels as specified in the screenshot attached.
You can follow the following steps to achieve the desired result:
  • Use the 'findgroups' function on the 'Filename' column to group the rows by filename.
% Considering 'data' variable to be the table
% I have named the first column as 'FileName'
[G, fileNames] = findgroups(data.FileName);
  • Use the 'splitapply' function to combine the labels for each group into a single array or cell.
% I have named the second column as 'Var2'
combinedVar2= splitapply(@(x) {x}, data.Var2, G);
% I have named the third column as 'Labels'
combinedLabels = splitapply(@(x) {x}, data.Labels, G);
  • Construct a new table with unique file names and combined labels.
combinedData = table(fileNames, combinedVar2, combinedLabels, 'VariableNames', {'FileName', 'Labels'});
% 'combinedData' would consist of unique filenames with combined cell elements in the 'Var2' and 'Labels' columns
You can refer to the following Mathworks documentations to know more about these functions:
Hope this helps!

Categorie

Scopri di più su Statistics and Machine Learning Toolbox in Help Center e File Exchange

Prodotti


Release

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by