How to update comparison expression as the loop updates ?

1 view (last 30 days)
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 Comments
KSSV
KSSV on 7 Mar 2017
What is comparison expression? You have to give an example, your question is not clear.
kintali narendra
kintali narendra on 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.

Sign in to comment.

Accepted Answer

KSSV
KSSV on 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.

More Answers (0)

Categories

Find more on Characters and Strings in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!