Finding specific phrases within a cell array (1)

Greetings,
I am working with a total of nine(9) text strings within nine(9) cell ( {9x1} )
and I am trying to take specific sentences of the text strings.
For example, one text string says:
EAST WINDS 15 TO 20 KNOTS. SEAS 4 TO 6 FEET.
I am trying to divide these two sentences in two structured variables under the name Today.
Today.Winds = EAST WINDS 15 TO 20 KNOTS
Today.Waves = SEAS 4 TO 6 FEET
The 9 different strings represents the 7 days of the week, plus today and night forecast, resulting in 9 different strings
The other strings outputs would go like this:
Tonight.Winds = EAST NORTHEAST WINDS 10 TO 14 KNOTS
Tonight.Waves = SEAS 3 TO 5 FEET
Monday.Winds = EAST WINDS 14 TO 19 KNOTS
Monday.Waves = SEAS 4 TO 6 FEET
I was thinking of telling MATLAB to break when he reaches the first dot and imprint the string as Today.wind, then continue till the next dot, break and imprint it as Today.waves.
How can I do this?
Thank you for your time.

2 Kommentare

Jan
Jan am 16 Jul. 2012
Please stop posting multiple questions about one problem. What should happen with the thread http://www.mathworks.com/matlabcentral/answers/43667-finding-specific-phrases-within-a-cell-array now? Such duplicate questions confuse the readers. It is better to add new information by editing the original question and to mark changes by adding the key "[EDITED]".
Juan Rosado
Juan Rosado am 17 Jul. 2012
My apologies. It won't happen again.

Melden Sie sich an, um zu kommentieren.

 Akzeptierte Antwort

C.J. Harris
C.J. Harris am 16 Jul. 2012

1 Stimme

See 'strtok' as one possible solutions. For example:
celltxt{1} = 'EAST WINDS 15 TO 20 KNOTS. SEAS 4 TO 6 FEET.';
[tok, rem] = strtok(celltxt{1}, '.');
Tonight.Winds = tok;
Tonight.Waves = rem(3:end-1); % removing first two and last character

6 Kommentare

C.J.,
Thank you for the idea, but some of the string have irregularities.
For example, one string instead of ending with a dot, ends with the first word of the presedign sentence.
EAST WINDS 16 TO 21 KNOTS. SEAS 4 TO 6 FEET. SCATTERED
In consequence, MATLAB outputs this string
'SEAS 4 TO 6 FEET. SCATTERE'
C.J. Harris
C.J. Harris am 17 Jul. 2012
Bearbeitet: C.J. Harris am 17 Jul. 2012
In this case you would have to pass the string through the strtok function to again separate them at the full stop. There is no harm passing the 'rem' string though the strtok function again. For example:
celltxt{1} = 'EAST WINDS 15 TO 20 KNOTS. SEAS 4 TO 6 FEET. SCATTERED';
[tok, rem] = strtok(celltxt{1}, '.');
Tonight.Winds = tok;
Tonight.Waves = strtok(rem(3:end), '.');
Sorry for asking so much Harris, is just that I'm about to finish a two month's work. I have this last problem. Some strings end in the start of the preceding string.
For instance,
EAST NORTHEAST WINDS 13 TO 16 KNOTS. SEAS 3 TO
5 FEET. SCATTERED SHOWERS AND ISOLATED THUNDERSTORMS.
In this case, MATLAB only outputs
Winds: 'EAST NORTHEAST WINDS 13 TO 16 KNOTS'
Waves: 'SEAS 3 TO'
What could I do?
Once again Thank you very much for your help and time.
Juan, "flagging" a message is to bring it to the attention of the moderators in order for them to decide whether to delete it (or to edit out rudeness.) Flagged messages are not brought to the attention of someone you are corresponding with. I don't think you meant to ask the moderators whether your comments were acceptable.
C.J. Harris
C.J. Harris am 18 Jul. 2012
Well Juan, that would all depend on how you are storing the text. Are you using a cell array?
Juan Rosado
Juan Rosado am 18 Jul. 2012
Indeed Harris I am using cell array and sorry for the flag.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Community Treasure Hunt

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

Start Hunting!

Translated by