Effacer les filtres
Effacer les filtres

use of strmatch to find a string NOT at the start of a line

2 vues (au cours des 30 derniers jours)
Matthew O'Brien
Matthew O'Brien le 9 Août 2011
Hi I have some data:
  1. PeakType Center Height Area FWHM parameters%_1 Linear x x x x 74.6852 -33.1093%_2 PseudoVoigt 0.728123 49.5433 1.78981 %_2 PseudoVoigt 0.728123 49.5433 1.78981
and this is stored is a cell array (in this case with a size of 4 and called 'everything'). now i can do the following to find the index of all occurrences of %_2:
findName = '%_2';
occurence = strmatch(findName,everything);
However what i need to do is simply find the index of where the string PseudoVoigt occurs (as it will not always start with %_2). I cannot use:
findName = 'PseudoVoigt';
occurence = strmatch(findName,everything);
Is there anyway i can do this without resorting to matlabs other strng matching functions and loops? If not then i think it would be very useful if this function could have an option to allow you to search in this way.
Thanks
Matt

Réponse acceptée

Oleg Komarov
Oleg Komarov le 9 Août 2011
idx = strfind(everything,'PseudoVoigt')
idx = ~cellfun('isempty',idx)
idx is logical true whenever it finds PseudoVoigt in any part of the string.

Plus de réponses (1)

Friedrich
Friedrich le 9 Août 2011
  1 commentaire
Matthew O'Brien
Matthew O'Brien le 9 Août 2011
Thanks to both of you for the answer. The output is not exactly the same as you get empty values where the string is not found and rather than the index of the occurrence you get the index of the start position of the search string but i think that i can still use this.
Still it would be useful to have a switch on strmatch to do this and obtain the same output.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Characters and Strings dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by