Remove rows from table identified in a second string array
显示 更早的评论
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
采纳的回答
更多回答(1 个)
Mathieu NOE
2021-4-13
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,:) = [];
类别
在 帮助中心 和 File Exchange 中查找有关 Agriculture 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!