Info
이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.
how to access contents of cell array using another cell array?
조회 수: 1 (최근 30일)
이전 댓글 표시
this is the code which opens a text file and finds the most occurring word in it which i named as kw.the count variable refers to indexes on which kw is present and index1 and index refers to the indexes of next and previous words to kw. can u help me to find the previous and next words to the kw instead instead of indexes on which these words are present? reply plz
fid = fopen('hello.txt');
text = textscan(fid,'%s');
fclose(fid);
[r,c]=size(text);
count = 0;
for i = 1:r
if(strcmp(text(i,1),kw) == 1)
count = [count,i];
end;
end;
[r1,c1] = size(count);
for i = 2:c1
index = count(i)-1
end;
for i = 2:c1
index1 = count(i)+1
end;
댓글 수: 1
Cedric
2013년 5월 3일
편집: Cedric
2013년 5월 3일
Are you sure that your code counts the most occurring word? It seems to me that the first loop creates an array of row IDs (and not counts) where the keyword is found, and the lines after are a little less clear. But in any case, it just counts the number of occurrences of one keyword.
Is it for a homework? Is the purpose really to find the most occurring word or is it to find the number of occurrences of one word? Could you use functions like UNIQUE, HISTC, ACCUMARRAY, or is it limited to FOR loops and STRCMP?
In any case, note that STRCMPI wouldn't be case sensitive, and that both STRCMP and STRCMPI can work on cell arrays and output a vector of comparison results (logicals).
답변 (0개)
이 질문은 마감되었습니다.
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!