writing a code involving struct

1 回表示 (過去 30 日間)
NUR KHAIRUNNISA rahimi
NUR KHAIRUNNISA rahimi 2011 年 11 月 8 日
I have a file with a list of words, and what I want to do is to keep the words in such an arrangement where it will turn out like this letters='abcdefghijklmn......xyz'
wordbank.a=airplane
aerosol
wordbank.b=bulky
big
best
wordbank.c=..... ....
until
wordbank.z=zebra ....
....
....
the whole code will be placed in a while loop, where every line in the word list will be processed and stored in the above arrangement. However I am not sure what is the right way of writing the code to make this happen.
Can somebody assist me with this?Thank you.
  1 件のコメント
NUR KHAIRUNNISA rahimi
NUR KHAIRUNNISA rahimi 2011 年 11 月 8 日
This page doesn't allow any space, therefore please know that the words are supposed to be kept in a [row,1] matrix

サインインしてコメントする。

回答 (1 件)

Fangjun Jiang
Fangjun Jiang 2011 年 11 月 20 日
For fun, just take all the text from TMW website and sort them according to the first letter and then put them into a word bank.
words=urlread('http://www.mathworks.com');
words=regexp(words,'[A-Za-z]*','match');
for letter='a':'z'
Wordbank.(letter)=words(strncmpi(words,letter,1));
end
  2 件のコメント
Walter Roberson
Walter Roberson 2011 年 11 月 20 日
'[A-Za-z]+'
would be a better search pattern: with the '*' it would also match the empty string, which occurs in _every_ line (including empty lines)
Fangjun Jiang
Fangjun Jiang 2011 年 11 月 20 日
It won't result in empty string as it searches only for 'A' to 'Z' and 'a' to 'z'. I ran any(cellfun('isempty',words)) and it didn't find any. However, using '+' is better than '*' as there is no change of zero match.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeStructures についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by