How to extract rows if column starts with a specific string?
9 ビュー (過去 30 日間)
古いコメントを表示
I have a data table that contains columns like this:
SampleName = {'13C3099';'13C3045';'14C3092';'14C3013'};
pH = [5.3822;4.382;4.9873;6.001];
Data = table(SampleName,pH)
I am trying to extract all the rows that have a sample name that starts with "13C". I have tried:
ExtractedRows = Data(:,Data.SampleName == '13C')
But I get the error "Undefined operator '==' for input arguments of type 'cell'." Can anyone help me identify what I am doing wrong?
0 件のコメント
採用された回答
Walter Roberson
2018 年 8 月 18 日
ExtractedRows = Data( startsWith(Data.SampleName,'13C'), : );
2 件のコメント
Image Analyst
2018 年 8 月 18 日
Nice to let people know of this new function. +1 vote. Will be useful to those who have R2016b or later.
Walter Roberson
2018 年 8 月 18 日
I think I learned it from Guillaume in https://www.mathworks.com/matlabcentral/answers/408631-finding-files-without-a-specfic-prefix-or-suffix-extension-etc-using-dir#answer_327337
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Characters and Strings についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!