Effacer les filtres
Effacer les filtres

How to update comparison expression as the loop updates ?

2 vues (au cours des 30 derniers jours)
kintali narendra
kintali narendra le 7 Mar 2017
I need to update my comparison expression , I dont know how to do it. All my comparison expressions are stored in a cells.
stringDAT = 'bat cat can car coat Name CUT ct CAT-scan'
expression = 'Name'
startIndex = regexp(stringDAT,expression)
I want the comparison expression need to be updated.
for i = 1:10
expression = value(i)
startIndex = regexp(StringDAT,expression)
where value has 10 different characters stored in form of cell.
thanku all
  2 commentaires
KSSV
KSSV le 7 Mar 2017
What is comparison expression? You have to give an example, your question is not clear.
kintali narendra
kintali narendra le 7 Mar 2017
sir , in we use string stored in 'expression' to compare with the data in 'stringDAT' , my question is, How we will update the string in 'expression' as the loop updates. As I have many values to compare.

Connectez-vous pour commenter.

Réponse acceptée

KSSV
KSSV le 7 Mar 2017
stringDAT = 'bat cat can car coat Name CUT ct CAT-scan'
% expression = 'Name' ;
% startIndex = regexp(stringDAT,expression) ;
value = {'apple' 'bat' 'cat' 'dog' 'car' 'cut' 'CUT'} ;
startIndex = NaN(size(value)) ;
for i = 1:length(value)
expression = value{i} ;
idx = regexp(stringDAT,expression) ;
if ~isempty(idx)
startIndex(i) = idx ;
end
end
Note that NaN means there is no matching.

Plus de réponses (0)

Catégories

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

Community Treasure Hunt

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

Start Hunting!

Translated by