Effacer les filtres
Effacer les filtres

Find several strings matching exact text

1 vue (au cours des 30 derniers jours)
bugguts99
bugguts99 le 9 Juin 2011
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?

Réponse acceptée

Walter Roberson
Walter Roberson le 9 Juin 2011
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 commentaire
bugguts99
bugguts99 le 9 Juin 2011
Walter...you are a star!

Connectez-vous pour commenter.

Plus de réponses (0)

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by