Comparing two excel files!
12 次查看(过去 30 天)
显示 更早的评论
I have two excel files with large amount of data. The cloumns in each file has the same title and same type of data. The data within the each column are combination of numerical values and text string (e.g. equiptment part number: 4F675HGYTV897). I also have some colums with numerical values and some with strings. I like to compare all of them.
I want to be able to compare columns and rows between the two files and report out the differnece.
Any help will be appreciated.
All the best,
Farshad
0 个评论
回答(1 个)
Pranjal Kaura
2020-6-19
Hey,
Here’s the code that compares 2 different excel files and stores the occurrence/index of any difference.
[~,~,raw1] = xlsread('pathtoFile1') ;
[~,~,raw2] = xlsread('pathtoFile2') ;
incorrectIndexes = zeros(size(raw1, 1), 2);%indexes stored in this array. Initialized for faster access/computation
numIncorrect = 0; % stores the count of number of differences encountered
if size(raw1) == size(raw2) % stop execution if unequal size
indexRows_error = find(all(cellfun(@isequal, raw1.', raw2.')) == 0); % compute index of rows, where there is a mismatch
% indexCols_error = find(all(cellfun(@isequal, raw1.', raw2.')) == 0); %compute index of cols where there is mimatch
% commented out the above method to showcase both the approaches for matching values.
% for loop approach
for indexrow = 1:length(indexRows_error)
row = indexRows_error(indexrow);
for col = 1:size(raw1, 2)
if(string(raw1{row, col}) ~= string(raw2{row, col}))
numIncorrect = numIncorrect + 1;
incorrectIndexes(numIncorrect, 1) = row;
incorrectIndexes(numIncorrect, 2) = col;
end
end
end
else
disp("Sizes of files unequal. Exiting");
end
1 个评论
KD
2025-4-28
Hello! I want to do this, but I want there to be a limit of how different the numerical values could be.
Ex. 15 plus/minus 1 (13 or 14) would still be correct
All of my values are numeric. Would the code be similar to this to do that?
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Spreadsheets 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!