Azzera filtri
Azzera filtri

Find several strings matching exact text

1 visualizzazione (ultimi 30 giorni)
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?

Risposta accettata

Walter Roberson
Walter Roberson il 9 Giu 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) = [];

Più risposte (0)

Prodotti

Community Treasure Hunt

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

Start Hunting!

Translated by