(matlab )从一个文本里,读出所有的英文单词,并且把所有以元音字母开头的

字母大写
2024-12-26 06:19:05
推荐回答(1个)
回答1:

比如下面这篇文章,复制粘贴到文本文档"article.txt"中去 Being depressed has been the obvious illness for some people nowadays. It has been noticed by the public. The news reported that some people got suicide because they had been suffered from depression for a long time. We felt so pity for the loss of these young lives, and they deserved living a better life if they had not passed away.When we saw the loss of young lives from the news, we felt sad and pity. The young people got suicide for many reasons, such as they got dumped by their girlfriends or boyfriends. Some children chose the extreme way to punish their parents after they had arguments. All of these reasons seemed can be solved in other people's eyes, there was no need to say goodbye to the world and miss the beautiful life.Life is short, we should cherish it and spend time on the things that can bring us happiness. Thinking about our parents and friends, they support us all the time. Love and care from these lovely people can help us get over all kinds of difficulties. 然后用以下程序得到所有英文单词和所有以元音字母开头的字母的单词 clc;clearfileName = 'article.txt';fid = fopen(fileName);str = fscanf(fid,'%c');num = double(str);idx =( num>=double('a')&num=double('A')&num<=double('Z'));words = cell(0);i = 1; m = 0;ew = '';% 读出所有单词for i= 1:1:numel(idx) if(idx(i)) ew = [ew,str(i)]; k1 = 0; else k1 = k1+1; if(k1 ==1) m = m+1; words = [words;ew]; end ew = ''; endend% 将首字母为元音的全部提取vowel = double('aeiouAEIOU');mynewwords = cell(0);for i = 1:1:numel(words) s = double(words{i,1}); if(any(s(1) == vowel)) mynewwords = [mynewwords;words{i}]; endend 结果如下所有单词: 所有元音字母为首字母的单词: