Filter löschen
Filter löschen

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

2 Ansichten (letzte 30 Tage)
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

Akzeptierte Antwort

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

Weitere Antworten (1)

Friedrich
Friedrich am 9 Aug. 2011
  1 Kommentar
Matthew O'Brien
Matthew O'Brien am 9 Aug. 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.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Characters and Strings finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by