Search a word in a workspace vektor.

3 views (last 30 days)
Hi,
I have a Vektor in the Workspace which includes a string.
Now I want to search a 'word' in this vector.
How can I do thios or can help me someone?
  2 Comments
Guillaume
Guillaume on 27 Apr 2015
Dennis' comment moved from Answer to here:
I´m going to explain it better:
My Workspace file look like this:
72 101 108 108 111 32 73 32 97 109 32 51 48 32 121 101 97 114 115 32 111 108 100 46
which means,
"Hello I am 30 years old.".
Now I want to search the word "years" in this Workspace file.
Guillaume
Guillaume on 27 Apr 2015
Edited: Guillaume on 27 Apr 2015
What is a 'workspace file'?

Sign in to comment.

Accepted Answer

Guillaume
Guillaume on 27 Apr 2015
I don't know what you mean by workspace file. Using proper terminology and examples that are valid matlab commands would help. Possibly you mean this:
v = [72 101 108 108 111 32 73 32 97 109 32 51 48 32 121 101 97 114 115 32 111 108 100 46];
s = char(v); %convert v into characters
yearloc = strfind(v, 'years')

More Answers (1)

Image Analyst
Image Analyst on 27 Apr 2015
If you mean search "FOR" a word, then this will work:
string = 'Now I want to search a "word" in this vector.'
location = strfind(string, 'word')
If you want to literally "search a word" for a particular letter, say 'r', then you can also use strfind() to search inside that word:
string = 'word'
location = strfind(string, 'r')

Categories

Find more on Environment and Settings 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!