필터 지우기
필터 지우기

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 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