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

2 次查看(过去 30 天)
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

采纳的回答

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

更多回答(1 个)

Friedrich
Friedrich 2011-8-9
  1 个评论
Matthew O'Brien
Matthew O'Brien 2011-8-9
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.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Characters and Strings 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by