Filter löschen
Filter löschen

How to update comparison expression as the loop updates ?

2 Ansichten (letzte 30 Tage)
kintali narendra
kintali narendra am 7 Mär. 2017
Kommentiert: kintali narendra am 7 Mär. 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 Kommentare
KSSV
KSSV am 7 Mär. 2017
What is comparison expression? You have to give an example, your question is not clear.
kintali narendra
kintali narendra am 7 Mär. 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.

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

KSSV
KSSV am 7 Mär. 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.

Weitere Antworten (0)

Kategorien

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

Community Treasure Hunt

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

Start Hunting!

Translated by