Data Processing in a Cell

Hello,
I have imported data into two tables T1 and T2 34243X4 and 1070X8. To Compare the two tables I have padded T2 with string 'empty' in all columns to match rows of T1. I am comparing T2(:,2) with T1(:,1) and which ever matches I then automatically the that particular row element in 4th Col of T2 will match row element of 1st Col in T1 (This acts as Sanity Check).
All the info in both the table is in string format including numbers
when I tried to use ismember is not able to match.
Did String Compare is not working or not comaring correctly.
Please could someone guide me. I have attached my code/script and also screenshots of my data.
Thank you for your time
PN = importdata("Part Number Summary 20260220.xlsx");
opts = detectImportOptions("Sai_MFGParts_03202026_v2.xlsx", Sheet="Export Worksheet");
% Adjust options if needed, for example set data range:
opts.DataRange = "A2";
T1 = readtable("Sai_MFGParts_03202026_v2.xlsx",opts);
T2 = PN.Summary;
C = T2; % rename for clarity
headers = C(1,1:8);
data = C(2:end,1:8);
varNames = matlab.lang.makeValidName(headers);
T2 = cell2table(data, 'VariableNames', varNames);
Part_Number_Data_T2 = T2.PartNumber;
Product_Description_T2 = T2.ProductDescription;
Supplier_T2 = T2.Supplier;
Categoty_T2 = T2.Category;
idx = length(T1.BWC_PART);
Part_Number_Data_T2 = resize(Part_Number_Data_T2,idx); % resize to match T1(34243x4)
Product_Description_T2 = resize(Product_Description_T2,idx);
Supplier_T2 = resize(Supplier_T2,idx);
Categoty_T2 = resize(Categoty_T2,idx);
idx_2 = cellfun('isempty',Part_Number_Data_T2);
idx_3 = cellfun('isempty',Product_Description_T2);
idx_4 = cellfun('isempty',Supplier_T2);
idx_5 = cellfun('isempty',Categoty_T2);
%Replace empty entries in Product_Description_T2, Supplier_T2, and
%Categoty_T2 with string 'empty'.
Part_Number_Data_T2(idx_2) = {'empty'};
Product_Description_T2(idx_3) = {'empty'};
Supplier_T2(idx_4) = {'empty'};
Categoty_T2(idx_5) = {'empty'};
%Ensure T2 columns are column vectors
Part_Number_Data_T2 = Part_Number_Data_T2(:);
Product_Description_T2 = Product_Description_T2(:);
Supplier_T2 = Supplier_T2(:);
Categoty_T2 = Categoty_T2(:);
Ind = cell(size(T1.BWC_PART));
for k = 1:length(Ind)
Ind{k} = T1(strcmp(T1.BWC_PART,Part_Number_Data_T2{k}),:);
end

4 Comments

would be nice to have the excel files to test your code
tx
I tried to mock up an example, but got an error with your code because we can't see all the columns of T2.
@Mathieu NOE, @Cris LaPierre Have added the Excel Files.
Cris LaPierre
Cris LaPierre 42 minutes ago
Edited: Cris LaPierre 32 minutes ago
Based on what I see in the code and your tables, I suspect you meant to say you are comparing T2(:,1) with T1(:,3), which both contain part numbers.
Can you also describe what the desired result is?

Sign in to comment.

 Accepted Answer

When combining data from 2 different tables, I would use the Join Tables task.
Since you want to only add data from another table if they have a matching value (called a key, which here appears to be part number), the final working code might look like this.
opts = detectImportOptions("Sai_MFGParts_03202026_v2.xlsx",'TextType','string', Sheet="Export Worksheet");
T1 = readtable("Sai_MFGParts_03202026_v2.xlsx",opts);
T2 = readtable("Part Number Su...20260220.xlsx",'TextType','string'); % Note a bug in Answers that truncates file names
Warning: Column headers from the file were modified to make them valid MATLAB identifiers before creating variable names for the table. The original column headers are saved in the VariableDescriptions property.
Set 'VariableNamingRule' to 'preserve' to use the original column headers as table variable names.
% Join tables
joinedData = outerjoin(T1,T2,Type="left",LeftKeys="BWC_PART", ...
RightKeys="PartNumber")
joinedData = 34243×12 table
MANUFACTURER_NAME MANFACTURER_PART BWC_PART PART_STATUS PartNumber ProductDescription Status Supplier Category Wetted_ WhereUsed_ SupplierPartNumber ______________________________ _________________ ___________ ___________ __________ __________________ _________ _________ _________ _______ __________ __________________ "W W GRAINGER INC" "5A989" "02-02-001" "Active" <missing> <missing> <missing> <missing> <missing> NaN NaN NaN "ALRO GROUP" "31422570" "02-02-002" "Active" <missing> <missing> <missing> <missing> <missing> NaN NaN NaN "ALRO GROUP" "80XR228 NORTON" "02-02-002" "Active" <missing> <missing> <missing> <missing> <missing> NaN NaN NaN "MSC INDUSTRIAL SUPPLY CO INC" "05984083" "02-02-002" "Active" <missing> <missing> <missing> <missing> <missing> NaN NaN NaN "MSC INDUSTRIAL SUPPLY CO INC" "85470698" "02-02-002" "Active" <missing> <missing> <missing> <missing> <missing> NaN NaN NaN "W W GRAINGER INC" "20RV34" "02-02-002" "Active" <missing> <missing> <missing> <missing> <missing> NaN NaN NaN "W W GRAINGER INC" "5A985" "02-02-002" "Active" <missing> <missing> <missing> <missing> <missing> NaN NaN NaN "MSC INDUSTRIAL SUPPLY CO INC" "05970504" "02-02-003" "Active" <missing> <missing> <missing> <missing> <missing> NaN NaN NaN "W W GRAINGER INC" "4F908" "02-02-003" "Active" <missing> <missing> <missing> <missing> <missing> NaN NaN NaN "ACTION INDUSTRIAL SUPPLY" "3M-81806-051144" "02-04-001" "Active" <missing> <missing> <missing> <missing> <missing> NaN NaN NaN "ACTION INDUSTRIAL SUPPLY" "3M-81806051144" "02-04-001" "Active" <missing> <missing> <missing> <missing> <missing> NaN NaN NaN "MSC INDUSTRIAL SUPPLY CO INC" "01209287" "02-04-001" "Active" <missing> <missing> <missing> <missing> <missing> NaN NaN NaN "W W GRAINGER INC" "2FWY8" "02-04-001" "Active" <missing> <missing> <missing> <missing> <missing> NaN NaN NaN "W W GRAINGER INC" "2JEN4" "02-04-001" "Active" <missing> <missing> <missing> <missing> <missing> NaN NaN NaN "MSC INDUSTRIAL SUPPLY CO INC" "01958909" "02-04-002" "Active" <missing> <missing> <missing> <missing> <missing> NaN NaN NaN "MSC INDUSTRIAL SUPPLY CO INC" "1144-81375" "02-04-002" "Active" <missing> <missing> <missing> <missing> <missing> NaN NaN NaN
If the partnumber from T1 is found in T2, the corresponding row from T2 is added to the right of the matching row in T1. If no match is found, then the row is filled with <missing> and nan instead.
Here is a view where there are some matches.
joinedData(13318:13335,:)
ans = 18×12 table
MANUFACTURER_NAME MANFACTURER_PART BWC_PART PART_STATUS PartNumber ProductDescription Status Supplier Category Wetted_ WhereUsed_ SupplierPartNumber _________________________________________________ ________________ ______________ ___________ ______________ ____________________________________ _________ ___________________________ _________ _______ __________ __________________ "LABELTAPE INC" "3378302" "238-81615-00" "Active" <missing> <missing> <missing> <missing> <missing> NaN NaN NaN "ENDRIES INTERNATIONAL INC" "WCRV" "239-02048-00" "Active" "239-02048-00" "PLUG 1" NPT SQ SOCKET" "Active" "ENDRIES INTERNATIONAL INC" "PLUG" NaN NaN NaN "MANUFACTURERS SUPPLY COMPANY" "200-11088" "239-02048-00" "Active" "239-02048-00" "PLUG 1" NPT SQ SOCKET" "Active" "ENDRIES INTERNATIONAL INC" "PLUG" NaN NaN NaN "ENDRIES INTERNATIONAL INC" "HFXK6" "239-02052-00" "Active" "239-02052-00" "BUSHING-1" NPT X 3/4" NPT GALV." "Active" "ENDRIES INTERNATIONAL INC" <missing> NaN NaN NaN "ENDRIES INTERNATIONAL INC" "HY4JM" "239-02052-00" "Active" "239-02052-00" "BUSHING-1" NPT X 3/4" NPT GALV." "Active" "ENDRIES INTERNATIONAL INC" <missing> NaN NaN NaN "MANUFACTURERS SUPPLY COMPANY" "200-11198" "239-02052-00" "Active" "239-02052-00" "BUSHING-1" NPT X 3/4" NPT GALV." "Active" "ENDRIES INTERNATIONAL INC" <missing> NaN NaN NaN "MANUFACTURERS SUPPLY COMPANY" "100-00003" "239-02067-00" "Active" <missing> <missing> <missing> <missing> <missing> NaN NaN NaN "MANUFACTURERS SUPPLY COMPANY" "200-01480" "239-02067-00" "Active" <missing> <missing> <missing> <missing> <missing> NaN NaN NaN "ENDRIES INTERNATIONAL INC" "0P18" "239-04474-00" "Active" "239-04474-00" "COUPLING-REDUCER 3/4 NPT X 1/2 NPT" "Active" "ENDRIES INTERNATIONAL INC" <missing> NaN NaN NaN "MANUFACTURERS SUPPLY COMPANY" "200-11085" "239-04474-00" "Active" "239-04474-00" "COUPLING-REDUCER 3/4 NPT X 1/2 NPT" "Active" "ENDRIES INTERNATIONAL INC" <missing> NaN NaN NaN "MANUFACTURERS SUPPLY COMPANY" "30108530" "239-04474-00" "Active" "239-04474-00" "COUPLING-REDUCER 3/4 NPT X 1/2 NPT" "Active" "ENDRIES INTERNATIONAL INC" <missing> NaN NaN NaN "USFLOW BERTSCH DIV NATIONAL CITY BANK HILCO REC" "30108530" "239-04474-00" "Active" "239-04474-00" "COUPLING-REDUCER 3/4 NPT X 1/2 NPT" "Active" "ENDRIES INTERNATIONAL INC" <missing> NaN NaN NaN "ENDRIES INTERNATIONAL INC" "0PD8" "239-05972-00" "Active" <missing> <missing> <missing> <missing> <missing> NaN NaN NaN "MANUFACTURERS SUPPLY COMPANY" "200-11282" "239-05972-00" "Active" <missing> <missing> <missing> <missing> <missing> NaN NaN NaN "ENDRIES INTERNATIONAL INC" "H0W19" "239-11638-00" "Active" "239-11638-00" "PLUG-3/4" NPT X SQ SOCKET" "Active" "ENDRIES INTERNATIONAL INC" "PLUG" NaN NaN NaN "MANUFACTURERS SUPPLY COMPANY" "200-08739" "239-11638-00" "Active" "239-11638-00" "PLUG-3/4" NPT X SQ SOCKET" "Active" "ENDRIES INTERNATIONAL INC" "PLUG" NaN NaN NaN

1 Comment

Thanks a Ton. I wasn't aware of right Keys Option.

Sign in to comment.

More Answers (0)

Categories

Products

Release

R2025a

Asked:

on 2 Apr 2026 at 13:17

Edited:

about 23 hours ago

Community Treasure Hunt

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

Start Hunting!