Include rows containing specific value
5 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Ninad Varkhede
am 29 Aug. 2024
Beantwortet: Lei Hou
am 9 Sep. 2024
I have a 1400*9 table (1400 rows and 9 columns) in MATLAB workspace. Each column has a different name. I want to select rows containing specific value. For example, how can I create a new table containig all rows with value of 0.456 in the column named "Biology"? I tried to use following code, but it gave error.
newData=[Data(find(Data.Biology == 0.456, :))]
0 Kommentare
Akzeptierte Antwort
Star Strider
am 30 Aug. 2024
the value you are searching for. 0.456, may not be the exact value.
Example —
Data = array2table(randn(10,9), 'VariableNames',{'A','Biology','C','D','F','G','H','I','J'});
Data{[2 5 9],2} = 0.456 + randn(3,1)*1E-9 % Create Inexact Values
idx = ismembertol(Data.Biology, 0.456, 1E-4)
numidx = find(idx)
NewData = Data(numidx,:)
The ismembertol function returns a logical vector. To get numeric indices, use find with it.
You may need to adjust the tolerance to work with your data, however this approach should work.
.
2 Kommentare
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!