VertCat unique rows of multiple tables.
15 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
MC
am 25 Apr. 2022
Kommentiert: Bruno Luong
am 25 Apr. 2022
Hi All,
I've got myself in a bit of a muddle and am looking for some help.
I have a number of tables containing the same variables but different rows of data. Some of the data is duplicated between tables.
The first column contains filenames stored in a categorical array.
I would like to vertically concatenate the tables after filtering out duplicate rows of data defined by duplicate filenames.
Is there a way to check for duplicates within two separate category arrays, then use that as a logical mask to select the rows to append.
%% Example Table structure.
tAll = table( 'Size' ,[0,5],...
'VariableNames' ,{'FileName' ,'SampleNumber' ,'DataType' ,'Value' ,'cellData'},...
'VariableTypes' ,{'categorical' ,'uint8' ,'categorical' ,'double' ,'cell'});
So what I want to do is something like...
tAll = [ t1 ; t2(t2.FileName ~= categories(t1.FileName))] % this doesn't work because t1.FileName and t2.FileName are arrays
I understand Joining tables wouldn't be appropriate, as there is no relationship as such, they are all the same variables.
I have also tried...
tAll = union( t1 ; t2 ); % this give an error because one variable contains random numbers of cells.
% Error using tabular/union (line 42)
% Unable to group rows using unique values of the table variable 'cellData'. UNIQUE returned an error.
% Caused by:
% Error using matlab.internal.math.uniqueCellstrHelper
% Cell array input must be a cell array of character vectors.
TIA, MC.
0 Kommentare
Akzeptierte Antwort
Bruno Luong
am 25 Apr. 2022
% dummy test data
Filename1=["a"; "b"; "c"];
Data1=["a1"; "b1"; "c1"];
T1=table(Filename1,Data1,'VariableNames',{'Filename','Data'})
Filename2=["a"; "d"];
Data2=["a2"; "d2"];
T2=table(Filename2,Data2,'VariableNames',{'Filename','Data'})
[~,i]=setdiff(T2.Filename, T1.Filename);
[T1; T2(i,:)]
2 Kommentare
Bruno Luong
am 25 Apr. 2022
You migh try
tAll = [T1; T2(~ismember(T2.Filename, T1.Filename),:)];
Weitere Antworten (1)
Siehe auch
Kategorien
Mehr zu Categorical Arrays finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!