append data at the end of cellarray?

3 次查看(过去 30 天)
  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 CenterFile Exchange 中查找有关 Large 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