Info

Questa domanda è chiusa. Riaprila per modificarla o per rispondere.

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

1 visualizzazione (ultimi 30 giorni)
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 Commento
Cedric
Cedric il 3 Mag 2013
Modificato: Cedric il 3 Mag 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).

Risposte (0)

Questa domanda è chiusa.

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by