フィルターのクリア

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) = [];
  1 件のコメント
bugguts99
bugguts99 2011 年 6 月 9 日
Walter...you are a star!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeString Parsing についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by