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.....
댓글 수: 1
Daniel Shub
2013년 4월 5일
What have you tried so far?
채택된 답변
추가 답변 (1개)
Jan
2013년 4월 5일
1 개 추천
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
Elysi Cochin
2013년 4월 5일
Elysi Cochin
2013년 4월 6일
편집: Elysi Cochin
2013년 4월 6일
Jan
2013년 4월 6일
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
2013년 4월 6일
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
2013년 4월 8일
카테고리
도움말 센터 및 File Exchange에서 Characters and Strings에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!