How can I extract data with respect to certain non numeric values

I have a csv file, which have numeric and non numeric columns. e.g the first, second and fourth column has numbers and the third column has letters i.e C,S,CA. I have imported the file and sorted the third (non-numeric) column so all the C, CA and S values are listed together. How can I extract rows of data that are associated with 'CA'? Thanks

 Réponse acceptée

Image Analyst
Image Analyst le 17 Avr 2016
Use readtable() to read your data into a table. Then use ismember() to find out which rows have CA in them, then use that to filter the rows. If you don't understand, then attach your data (csv file).

4 commentaires

Thanks Image Analyst Yes I am a bit confused so Please find attached a small part of the data set. I would like to import the file into Matlab and extract all the rows related to the CA atom and store that data in a separate matrix. Thanks again
Try this:
t = readtable('sample data.csv')
% Extract column 2 only
col2 = t.atom_types
% Find out which rows in column 2 are 'CA'
caRows = ismember(col2, 'CA')
% Extract those rows ONLY into a new table.
caRowsInTable = t(caRows, :)
The final result:
caRowsInTable =
atom_type atom_types residue chain secondary_structures secondary_structures_begin
_________ __________ _______ _____ ____________________ __________________________
5 'CA' 1 32 99 39
5 'CA' 1 32 99 0
5 'CA' 2 32 99 40
5 'CA' 2 32 99 0
5 'CA' 3 32 99 125
Thanks Image Analysis. I am getting an error with readtable function 'Undefined function 'readtable' for input arguments of type 'char'. I have loaded my data but I seem to be missing the column names so if I wanted CAs out of column 2 could I use col2=t.(:,2) instead of col2 = t.atom_types? Cheers
Thanks Image Analysis. It worked!!

Connectez-vous pour commenter.

Plus de réponses (1)

Catégories

En savoir plus sur Large Files and Big Data dans Centre d'aide et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by