COMPGROUPS.NET | Search | Post Question | Groups | Stream | About | Register

### number of occurrences / storing strings in cells

• Email
• Follow

```i have the following text in a .txt file:

In what distant deeps or skies
Burnt the fire of thine eyes?
On what wings dare he aspire?
What the hand dare seize the fire?

how do i count the number of occurrences of the word 'what' in the file?  also, how do i split the poem into multiple strings in a cell array, using the question marks as separators?
```
 0

See related articles to this posting

```"Pr B" <pb2297@columbia.edu> wrote in message <hor3at\$5b7\$1@fred.mathworks.com>...
> i have the following text in a .txt file:
>
> In what distant deeps or skies
> Burnt the fire of thine eyes?
> On what wings dare he aspire?
> What the hand dare seize the fire?
>
> how do i count the number of occurrences of the word 'what' in the file?  also, how do i split the poem into multiple strings in a cell array, using the question marks as separators?

Could this question be accurately rephrased as "How do I do my homework?"  If so, maybe you could show post some of the code that you have already written trying to solve this, and we could give you some pointers?
```
 0

```actually, no.  i'm using it as an example for a much larger string / cell array project i'm working on.  feel free to comment on my approach below, though:

for counting the number of occurrences of 'what' (case insensitive), i'm using strfind

strfind(S, 'what')

where S is the input text.  however, S isn't a string but is instead a cell, which is why i'm having difficulty counting the number of occurrences.  do i need to import the data as an array, use cellstr, and then count the number of occurrences using strfind?

as for the storing in individual cells, well, i'm clueless.

"the cyclist" <thecyclist@gmail.com> wrote in message <hor3to\$e63\$1@fred.mathworks.com>...
> "Pr B" <pb2297@columbia.edu> wrote in message <hor3at\$5b7\$1@fred.mathworks.com>...
> > i have the following text in a .txt file:
> >
> > In what distant deeps or skies
> > Burnt the fire of thine eyes?
> > On what wings dare he aspire?
> > What the hand dare seize the fire?
> >
> > how do i count the number of occurrences of the word 'what' in the file?  also, how do i split the poem into multiple strings in a cell array, using the question marks as separators?
>
> Could this question be accurately rephrased as "How do I do my homework?"  If so, maybe you could show post some of the code that you have already written trying to solve this, and we could give you some pointers?
```
 0