Filter löschen
Filter löschen

Extract Data from Table by Data Values

5 Ansichten (letzte 30 Tage)
Sam P
Sam P am 7 Mai 2020
Bearbeitet: BhaTTa am 16 Jul. 2024 um 3:17
Hi all,
I am trying to extract rows matching one of multiple values but I am not sure which functions to use. I have a 9,857,445 x 3 table. The headers are in the 3 columns, and all 3 columns A,B, C, contain numerical data.
I am trying to extract based on data for the first column A. For example, I want to extract the rows that have the following values for A; A= 1, A=6, A=4 or A =12. Based on all the rows that match any of the possible listed values for A, I would like to create a new table Final Data, that only lists rows that match the given values for A. I am using 2015a.
Thanks for your help.

Antworten (1)

BhaTTa
BhaTTa am 16 Jul. 2024 um 3:05
Bearbeitet: BhaTTa am 16 Jul. 2024 um 3:17
You can achieve this by using logical indexing below is the implemetation:
% Example to create a sample table, replace this with your actual data loading
dataTable = array2table(randi(20, 9857445, 3), 'VariableNames', {'A', 'B', 'C'});
valuesToMatch = [1, 6, 4, 12];
% Logical indexing to find rows where column A matches any of the specified values
rowsToExtract = ismember(dataTable.A, valuesToMatch);
% Create the new table with the extracted rows
finalData = dataTable(rowsToExtract, :);
% Example: Save to a new file
writetable(finalData, 'finalData.csv');

Kategorien

Mehr zu Tables finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by