Find the missing rows and newly added rows in two different excels sheets

3 views (last 30 days)
Hello
I am comparing and finding out the missing rows and newly added rows data from two different excels sheets.
I have attached 3 files.
SummaryNew.xlsx and SummaryOld.xlsx are having data. Compare those 2 excel files.
  • SummaryResult.xlsx In a result, I am expecting 2 sheets. MissingData and NewlyAddedData.
Thank you!!
I tried using
diff_rows = find(all(cellfun(@isequal, SummaryOld', SummaryNew')) == 0);
similar_rows = find(all(cellfun(@isequal, SummaryOld', SummaryNew')) == 1);
bt it is just comparing one excel whole with other.

Accepted Answer

Akira Agata
Akira Agata on 19 Jul 2022
How about the following?
% Load the Excel files
tNew = readtable('https://jp.mathworks.com/matlabcentral/answers/uploaded_files/1069895/SummaryNew.xlsx',...
'VariableNamingRule','preserve');
tOld = readtable('https://jp.mathworks.com/matlabcentral/answers/uploaded_files/1069900/SummaryOld.xlsx',...
'VariableNamingRule','preserve');
% Newly Added data
idx = ismember(tNew, tOld, 'rows');
tNew(~idx,:)
ans = 2×4 table
PLD Status BLF File Name Time(sec) EgoSpeed(kmh) __________ ___________________ _________ _____________ {'ddd'} {'20220330_143818'} 2495.4 67.9 {'eee'} {'20220330_184617'} 3755.8 88.5
% Missing data
idx = ismember(tOld, tNew, 'rows');
tOld(~idx,:)
ans = 2×4 table
PLD Status BLF File Name Time(sec) EgoSpeed(kmh) __________ ___________________ _________ _____________ {'aaa'} {'20220330_101314'} 2101 56.1 {'bbb'} {'20220330_143818'} 2200 60
  4 Comments
Santosh Biradar
Santosh Biradar on 21 Jul 2022
Edited: Santosh Biradar on 21 Jul 2022
I have one more step need to add in the SummaryResult.
Your responce will be very helpful.
Eg.
In the SummaryResult Excel,
if A3 having value aaa and A6 also having aaa (like the same values present in A Column only) then Entire ROWS MissingData-sheet and NewlyaddedData-sheet will be written separately to new *AAA*Sheet in the Same SummaryResult.xlsx
if A4 having value bbb and A5 also bbb (the same values present in A Column only)then entire ROWS from MissingData-sheet and NewlyaddedData-sheet will be written separately to new *BBB* sheet in the Same SummaryResult.xlsx
I have attached upated Required SummaryResult.xlxs
Please have a look for ref. Sheet AAA and BBB
Thank you

Sign in to comment.

More Answers (0)

Products


Release

R2019b

Community Treasure Hunt

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

Start Hunting!