Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Comparison

0 views
Skip to first unread message

varun khanduja

unread,
Oct 4, 2008, 2:25:04 AM10/4/08
to
I am trying to run naive string matching in MATLAB..dont know where i am going wrong..have got fed up and finally thought of writing for some help on the forum.. The following is my code..It seems to be working for a single word as a pattern but when it comes to more than one word..it fails..I am sure there is some logical problem..just getting tired of not able to code such simple programs ..some one please try to help me conceptually if possible..i am new to programming and i m finding life really tough..


function[compare,in]=naive_search(t,p)
m=length(p);
n=length(t);
win=0;
if(n==0)
fprintf('the string is empty');
else if(m==0)
fprintf('the pattern is not present');
else
for counter=1:n-m
if (p(counter)==t(counter))
counter;
win=1+win;
end
win;
end
end

Husam Aldahiyat

unread,
Oct 4, 2008, 2:43:01 AM10/4/08
to
Try ismember and strcmp functions.

Bruno Luong

unread,
Oct 4, 2008, 3:09:02 AM10/4/08
to
"varun khanduja" <varunk...@gmail.com> wrote in message <gc7280$30v$1...@fred.mathworks.com>...


> for counter=1:n-m
> if (p(counter)==t(counter))
> counter;
> win=1+win;
> end
> win;
> end
> end

At each for loop iteration you should compare a substring of t with p.

What you did is just comparing one (1) character of each.

Bruno

0 new messages