How to extract all the rows which match an specific string column

조회 수: 127 (최근 30일)
Philippe Corner
Philippe Corner 2017년 11월 6일
댓글: Cristian Miculas 2022년 1월 26일
The data is organized on this way: 4 numeric columns and 3 string columns all of same dimentions. I need to build a matrix which contains all the columns in order to extract the rows who match with and specific geol_unit string.
%this is how i read the data:
[x,y,strike_dir,dip,town,geol_unit,source] = textread('DatosEstructurales_C&S.txt','%f %f %f %f %s %s %s','delimiter',';');
%next step would be to build a matrix to obtain something like:
x y strike_dir dip 'town' 'geol_unit' 'source'
1191292.27 824768.3 65 60 Medellin StockAltavista Microzonificacion_2007
1191237.46 825146.46 200 25 Medellin StockAltavista Microzonificacion_2007
1188070.99 825708.745 46 55 Medellin Dunita RecargaCyS_2013
1188070.99 825708.745 156 60 Medellin Dunita RecargaCyS_2013
The final idea is to find an specific geol unit match and extact all the values.. for example all Dunita values, and get a matrix like:
x y strike_dir dip 'town' 'geol_unit' 'source'
1188070.99 825708.745 46 55 Medellin Dunita RecargaCyS_2013
1188070.99 825708.745 156 60 Medellin Dunita RecargaCyS_2013

답변 (2개)

KL
KL 2017년 11월 6일
편집: KL 2017년 11월 6일
Use readtable to import your data,
T = readtable('DatosEstructurales_C&S.txt');
if you don't have column names included in your text file, then
T.Properties.VariableNames = {'x','y','strike_dir','dip','town','geol_unit','source'};
and now to get what you want,
T_dunita = T(T.geol_unit == 'Dunita',:)
read more about readtable and tables on the below links:
  댓글 수: 2
KAE
KAE 2020년 5월 5일
When trying to match a string in a table column,
T.geol_unit == 'Dunita'
I get the error
Undefined operator '==' for input arguments of type 'cell'.
Cristian Miculas
Cristian Miculas 2022년 1월 26일
use "Dunita" instead of 'Dunita' or strcmp(T.geol_unit, 'Dunita')

댓글을 달려면 로그인하십시오.


Craig
Craig 2020년 11월 9일
Use: T_dunita = strcmp(T.geol_unit, 'Dunita')

카테고리

Help CenterFile Exchange에서 Characters and Strings에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by