Borrar filtros
Borrar filtros

Find several strings matching exact text

1 visualización (últimos 30 días)
bugguts99
bugguts99 el 9 de Jun. de 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?

Respuesta aceptada

Walter Roberson
Walter Roberson el 9 de Jun. de 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) = [];

Más respuestas (0)

Categorías

Más información sobre String Parsing en Help Center y File Exchange.

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by