Remove rows from table identified in a second string array
Show older comments
Hi,
I have a table of results, called Results which is 505x11. The first column is Results.Filename and gives an asociated string file name for each set of results. I have a second cell array called Post_Inflate_names which is 191X1 and contains string names in the same format as Results.Filename.
I want to remove rows in Results if the filename is present in Post_Inflate_names. I have tired using the find command however there are limitations using the == operator with a table.
% One of the many failed attempts...
Remove = find(Results.Filename == Post_Inflate_names)
Results(Remove,:) = [];
I will include a few sample rows of both data in a spreadsheet.
Thanks,
Christopher
Accepted Answer
More Answers (1)
Mathieu NOE
on 13 Apr 2021
hello Christopher
thi would be my suggestion
notice I changed the last 3 names in Post_Inflate_names to get a matching case with {'001a'};{'001b'};{'001c'}
Results = readtable('sample.xlsx','VariableNamingRule','preserve');
% Post_Inflate_names = [{'003d'};{'004d'};{'006d'};{'007d'};{'008f'};{'009d'};{'010d'};{'011e'};{'014e'};{'015d'}];
Post_Inflate_names = [{'003d'};{'004d'};{'006d'};{'007d'};{'008f'};{'009d'};{'010d'};{'001a'};{'001b'};{'001c'}];
str1 = Results.Filename;
str1 = strrep(str1,'''',''); % simple quotes gone
str1 = strrep(str1,'"',''); %double quotes gone
str2 = Post_Inflate_names;
str2 = strrep(str2,'''',''); % simple quotes gone
str2 = strrep(str2,'"',''); %double quotes gone
[Names, Remove, DataIdx] = intersect(str1, str2, 'stable');
Results(Remove,:) = [];
Categories
Find more on Multidimensional Arrays in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!