필터 지우기
필터 지우기

Find several strings matching exact text

조회 수: 1 (최근 30일)
bugguts99
bugguts99 2011년 6월 9일
I need to find several strings in a 1 x 81 cell array that match exact text (see code below). My problem is that when using regexp a number of cells containing similar text are being identified and corresponding columns are removed from the dataset. For example, I have three columns with 'H', 'Hc' and 'Hs'. I want to identify 'H' only.
idx = regexp(cols,'H|n_Tot|fw_Avg|stdev_fw|cov_fw_Ux|cov_fw_Uy|cov_fw_Uz','match');
TF = cellfun('isempty', idx);
[r, c] = find(TF == 0);
Farm34Maize(:, c) = [];
cols(:, c) = [];
In addition, is there a more efficient way of acheiving this in fewer lines than above?

채택된 답변

Walter Roberson
Walter Roberson 2011년 6월 9일
idx = regexp(cols,'^(H|n_Tot|fw_Avg|stdev_fw|cov_fw_Ux|cov_fw_Uy|cov_fw_Uz)$','match');
You might consider
tf = ismember(cols, {'H','n_Tot', 'fw_Avg', 'stdev_fw', 'cov_fw_Ux', 'cov_fw_Uy', 'cov_fw_Uz});
Farm34Maize(:,tf) = [];
cols(:,tf) = [];

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 String Parsing에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by