please any one can understand me this and I want to display any word and here frq like city 3 .gg.txt contain this text I live in a city called hilla this city located in.the center of iraq it is not too large.hilla contain many resturants in her

조회 수: 3 (최근 30일)
stp_w={ 'I', 'called',' this' ,'in', 'the',' of', 'it', 'is', 'not' ,'too' ,'many' ,'here', 'these', 'one', 'and', 'that',};
f = fopen('gg.txt','r');
I = textscan(f,'%s',100);
d=I{1};
for i=1:length(d)
x = strmatch(d(i), stp_w);
c=0;
if x~=1
for j=1:length(d)
x = strmatch(d(i),d(j) );
if x==1
c=c+1;
end
end
feq(i)=c;
end
end

채택된 답변

KSSV
KSSV 2016년 12월 9일
clc; clear all ;
stp_w={ 'I', 'called',' this' ,'in', 'the',' of', 'it', 'is', 'not' ,'too' ,'many' ,'here', 'these', 'one', 'and', 'that',};
f = fopen('gg.txt','r'); % opens text file gg.txt
I = textscan(f,'%s',100); % scans the data into strings in I
d=I{1}; % the first line
for i=1:length(d) % loop for every data in first line
x = strmatch(d(i), stp_w); % matching each string in d with stp_w
c=0; % a constant c = 0, for count
if x~=1 % if string is not matching
for j=1:length(d) % loop for every data in first line
x = strmatch(d(i),d(j) ); % comapring the strings in text file with it selfs
if x==1 % is string matches
c=c+1; % count increased
end
end
feq(i)=c; % saving ht ecount
end
end
  댓글 수: 1
hiba rashed
hiba rashed 2016년 12월 9일
thanks a lot and how can I find the frequency of each answer like this ex? ex/ city 3 Hilla 2 these words in gg.txt

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Entering Commands에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by