This question is closed. Reopen it to edit or answer.

how to access contents of cell array using another cell array?

1 view (last 30 days)
shafaq innam
shafaq innam on 3 May 2013
Closed: MATLAB Answer Bot on 20 Aug 2021
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');
count = 0;
for i = 1:r
if(strcmp(text(i,1),kw) == 1)
count = [count,i];
[r1,c1] = size(count);
for i = 2:c1
index = count(i)-1
for i = 2:c1
index1 = count(i)+1
  1 Comment
Cedric Wannaz
Cedric Wannaz on 3 May 2013
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).

Answers (0)


Community Treasure Hunt

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

Start Hunting!

Translated by