How to split a table into multiple tables based on value in a column?
5 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
KD
am 19 Mär. 2025
Bearbeitet: Cris LaPierre
am 20 Mär. 2025
Hello,
I am reading in an excel file that has 2 columns of data. One of them has a lot number and the other has row/col numbers.
I've made a table that holds this information, however, I would like to make multiple tables for every set of lot numbers.
I've attached an example excel sheet. In this example there are 2 different lot numbers, so I would need it to make 2 different tables for each lot number with each corresponding row, col number! I also need it to be able to adjust if there are more than 2 different lot numbers because the sheet is always updated.
Thanks!
3 Kommentare
Stephen23
am 19 Mär. 2025
Often splitting up data makes it harder to process. Consider instead:
Akzeptierte Antwort
Cris LaPierre
am 19 Mär. 2025
There are several possible approaches based on what you need. Here's one that creates a cell array of tables, one for each unique lot number.
data = readtable ('ExampleExcel.xlsx');
% Convert RC to numeric arrays
tmp = cellfun(@str2num,data.RC,'UniformOutput',false);
data.RC = cell2mat(tmp);
% find unique LotNumbers
G = findgroups(data.LotNumber);
% Split data into table for each lot number
tblLN = splitapply(@(x1,x2){table(x1,x2)},data,G)
% view first table
tblLN{1}
2 Kommentare
Cris LaPierre
am 19 Mär. 2025
Bearbeitet: Cris LaPierre
am 20 Mär. 2025
I'll reiterate the comments above. I would probably look to groupsummary, but we'd need to know more about what your end goal is to say for certain.
data = readtable ('ExampleExcel.xlsx');
% Convert RC to numeric arrays
tmp = cellfun(@str2num,data.RC,'UniformOutput',false);
data.RC = cell2mat(tmp);
% find max ID for each unique LotNumber
mxID = groupsummary(data,'LotNumber','max')
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Tables finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!