フィルターのクリア

append data at the end of cellarray?

1 回表示 (過去 30 日間)
arun
arun 2013 年 9 月 29 日
回答済み: arun 2013 年 9 月 29 日
  1. fid = fopen('TEXTFILE.txt','r');
  2. tline = fgets(fid);
  3. while ischar(tline)
  4. words=regexp(tline,'<s>|\w*|</s>','match');
  5. * trigram=cellfun(@(x,y,z) [x ' ' y ' ' z],words(1:end-2), words(2:end-1),words(3:end),'un',0); *
  6. tline = fgets(fid);
  7. end
  8. fclose(fid);
  9. uniquetrigram = unique(trigram);
  10. counts = cellfun(@(x)sum(strcmp(x,trigram)), uniquetrigram);
  11. % Group them together
  12. trigramcount = [uniquetrigram.' num2cell(counts.')]';
QUERY: I have problem in line number "5" because every time i want to store the output at the end of "trigram" cell array but it is storing the out of last line only. Every time i want to append the output of "* cellfun(@(x,y,z) [x ' ' y ' ' z],words(1:end-2), words(2:end-1),words(3:end),'un',0); *" in to "trigram" how can i do this?

採用された回答

arun
arun 2013 年 9 月 29 日
I have solved this in following way. This is the solution i am using.
fid = fopen('Tiny_Corpus.txt','r');
tline = fgets(fid);
trigram={};
while ischar(tline)
words=regexp(tline,'|\w*|','match');
trigram1=cellfun(@(x,y,z) [x ' ' y ' ' z],words(1:end-2), words(2:end-1),words(3:end),'un',0);
trigram = [trigram trigram1];
tline = fgets(fid);
end
fclose(fid);
uniquetrigram = unique(trigram);
counts = cellfun(@(x)sum(strcmp(x,trigram)), uniquetrigram);
% Group them together
trigramcount = [uniquetrigram.' num2cell(counts.')]';

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLarge Files and Big Data についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by