How to compare two different excel sheets specific columns for like values

I am trying to compare two excel files, specifically a column in each. The cells contain numbers and letters and arent in order. I am trying to update a condensed list to ensure that it has the master's values. It has been a few years since ive used MATLAB. I tried using the setdiff function to compare arrays from each with no luck. TIA!

7 Comments

Can you attach the files and show how you have used setdiff()? You may want to use ismember() in this situation.
I cannot attach the files. Im trying to do something like this:
A = xlsread('File1.xlsx'); %Full list
B = xlsread('File2.xlsx'); %Condensed list
C = setdiff(A,B);
I realize that I havent called on the specific columns. The display is showing mostly NaN's
Data in column 3 of the condensed list comparing to data of Column 13 of the full list. values contain numbers and letters ex. "abc123456". One column is larger than the other, and values are out of order. Im trying to figure out what values are on the full that arent on the condensed. TIA
[edited to reflect your latest comment] You mention the cells contain letters and numbers. If these are all important, you probably want to use the third output from xlsread(), which preserves the cell data without interpreting it as numbers or text (which are the first two outputs, respectively - you'll get NaNs where the cell has text when you use the numeric first output). Try it like this:
[~,~,A] = xlsread('File1.xlsx'); %Full list
[~,~,B] = xlsread('File2.xlsx'); %Condensed list
A = A(:,13);
B = B(:,3);
% C = setdiff(A,B); % probably also OK
C = A(~ismember(A,B)); % Full list elements not in Condensed list
Thank you for the quick reply! Im finally getting something other than NaN. In "Variables - inccorectIndexes" There are two columns of 0 or "falses". When running an audit on excel, most values from the condensed are not on the full.
I thought you want to find out which values in the full list aren't in the condensed list:
C = A(~ismember(A,B)); % Full list elements not in Condensed list
rtather than which values in the condensed list aren't in the full list:
D = B(~ismember(B,A)); % Condensed list elements not in Full list
I tried both C and D. Unfortunately that didnt work. Thank you though!

Sign in to comment.

Answers (1)

xlsread is deprecated, avoid it.
fullTab = readtable('File1.xlsx');
denseTab = readtable('File2.xlsx');
[idxFull, idxDense] = ismember(fullTab.(13), denseTab.(3));
idxDense(idxDense < 1) = [];
fullCol13Unique = A.(13)(~idxFull);

Categories

Asked:

on 21 Jan 2022

Commented:

on 24 Jan 2022

Community Treasure Hunt

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

Start Hunting!