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:
'findgroups': https://www.mathworks.com/help/releases/R2024a/matlab/ref/findgroups.html?searchHighlight=findgroups&s_tid=doc_srchtitle
'splitapply': https://www.mathworks.com/help/releases/R2024a/matlab/ref/splitapply.html?searchHighlight=splitapply&s_tid=doc_srchtitle
Hope this helps!