Data Processing in a Cell
Show older comments
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
Mathieu NOE
3 minutes ago
would be nice to have the excel files to test your code
tx
Cris LaPierre
1 minute ago
I tried to mock up an example, but got an error with your code because we can't see all the columns of T2.
Sai Gudlur
34 minutes ago
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?
Accepted Answer
More Answers (0)
Categories
Find more on Tables in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!