Include rows containing specific value
1 view (last 30 days)
Show older comments
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 Comments
Accepted Answer
Star Strider
on 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 Comments
See Also
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!