search pattern without using built -in function
Show older comments
how to search pattern without using regexp or strcmp function.... that is if i have a word "mississippi" the string "issi" "ssi" "ss"..... occurs two times.... how to write it in code without using built-in function..... how to search whether a particular pattern is in the word and its occurance without using built-in function...... please do reply.....
1 Comment
Daniel Shub
on 5 Apr 2013
What have you tried so far?
Accepted Answer
More Answers (1)
Jan
on 5 Apr 2013
1 vote
Sorry, without built-in functions you cannot perform any useful operations in Matlab. Even the assignment using the "=" operator is a built-in function.
6 Comments
Elysi Cochin
on 5 Apr 2013
Elysi Cochin
on 6 Apr 2013
Edited: Elysi Cochin
on 6 Apr 2013
Jan
on 6 Apr 2013
I do not have any chance to guess, what built-in function belong to "those" functions, and which are allowed. Are you looking for the term "agca" in horizontal, vertical and diagonal directions? How do you think could the occurrences be "highlighted"? This might be an overly complicated method.
You get the error message, because REGEXP finds multiple occurrences, and you want to store them in a scalar element.
What about a dull FOR loop through the vectors and comparing the parts of the strings by isequal()?
Elysi Cochin
on 6 Apr 2013
The way you are using REGEXP makes it return an array of starting positions of the pattern in the array of characters that you are passing as a first argument.
You seem to have defined BWM as a rectangular array of characters, why? As Jan mention, should we understand that you have to find vertical occurrences or should we read BWM horizontally as if it were one long string? If such case, you could redefine it as
BWM = BWM(:).' ;
in order to make it easier for us to understand that it is just one long string and to simplify further processing
Now let's admit that it is just one long string, could you exploit a FOR loop like the following for searching the pattern?
for k = 1 : length(BWM)-length(expression)+1
% do something
end
If you have to "highlight" matches by framing them with stars, you could for example build a second BWM while you read the first, which would include the stars (might be easier than try to insert stars in the current version).
Elysi Cochin
on 8 Apr 2013
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!