search pattern without using built -in function

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

 Réponse acceptée

doc regexp

1 commentaire

sir but regexp is a built-in function..... is it possible to do without any built-in function?? please do reply.....

Connectez-vous pour commenter.

Plus de réponses (1)

Jan
Jan le 5 Avr 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 commentaires

sorry sir... i didnt mean all built-in functions.... but those like strcmp and regexp..... only those i meant not to use......
Elysi Cochin
Elysi Cochin le 6 Avr 2013
Modifié(e) : Elysi Cochin le 6 Avr 2013
sir i have an output as below.... BWM a 12*12 char array....
BWM =
$agcagcagact
act$agcagcag
agact$agcagc
agcagact$agc
agcagcagact$
cagact$agcag
cagcagact$ag
ct$agcagcaga
gact$agcagca
gcagact$agca
gcagcagact$a
t$agcagcagac
from this output i want to search the pattern "agca"... where it occurs and how many times..... can you show me using built-in functions???..... if possible can you highlight those portions or draw a bounding box in the output..... please do reply sir.... sir for eg:in the word "agcagcagcagc" if i have to find pattern "agac" i want the output *agca*gcagcagc, agc*agca*gcagc, agcagc*agca*gc
but when i use regexp i get only
startIndex =
1 7
please if possible can you help me to solve this also.....
i did as below...
k = 1;
expression = 'gca';
for i = 1 : 12
startIndex(1, k) = regexp(BWM(i),expression)
k = k + 1;
end
but i'm getting error....
??? Subscripted assignment dimension mismatch.
Error in ==> usage_BurrowsWheelerTransform at 16
startIndex(1, k) = regexp(BWM(i),expression)
please do reply.....
Jan
Jan le 6 Avr 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()?
sir neednt look to my code.... i know its wrong.... please can you post the correct coding sir??.... please do reply....
Cedric
Cedric le 6 Avr 2013
Modifié(e) : Cedric le 6 Avr 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).
thank u all

Connectez-vous pour commenter.

Catégories

En savoir plus sur Characters and Strings dans Centre d'aide et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by