### Translated by

このページのコンテンツは英語から自動翻訳されています。自動翻訳をオフにする場合は「<a class="turn_off_mt" href="#">ここ</a>」をクリックしてください。

## How can i find the all the positions of elements in cell and record them all in an the same cell

VINH CHI HA

### VINH CHI HA (view profile)

さんによって質問されました 2019 年 5 月 6 日

### Andrei Bobrov (view profile)

さんによって 回答されました 2019 年 5 月 6 日
How can i find the all the positions of elements in cell and record them all in an the same cell ?
the following code gives me a cell with a column showing each word splitted, but i also need to know positions of them in text file.
for example : apple napkin bus bus kid, the result looking for is : bus 2 3 4 napkin 1 2 kid 1 5 apple 1 1.
the first number is their frequency , the follwing numbers are their positions
fid=lower(fid); %convert letters to lower case
fid=regexprep(fid,'\W',' '); %regexprep to replace any character that is not alphabetic using \W with space ' '
words=regexp(fid,' ','split'); %using space ' ' to split words then put into cell
rank=tabulate(words); %compute the frequency
ans=sortrows(rank,-2); %sort the frequency

KSSV

### KSSV (view profile)

2019 年 5 月 6 日
YOu should attach your text file.
VINH CHI HA

### VINH CHI HA (view profile)

2019 年 5 月 6 日
my file is updated now, thank you

サインイン to comment.

## 2 件の回答

### KSSV (view profile)

2019 年 5 月 6 日

fid = fopen('data.txt','rt') ;
S = textscan(fid,'%s','delimiter','\n') ;
S = S{1} ;
fclose(fid) ;
S = strsplit(S{1})' ;
idx = contains(S,'network') ;
iwant = {'network',nnz(idx),find(idx)}

#### 0 件のコメント

サインイン to comment.

### Andrei Bobrov (view profile)

2019 年 5 月 6 日

f = fopen('data.txt'); str = textscan(f,'%s','delimiter','\n'); fclose(f);
str = regexp(str{1},'\w+','match','once');
[a,b,c] = unique(str(:),'stable');
out = [a,num2cell(accumarray(c,1)),accumarray(c,(1:numel(c))',[],@(x){x})];

#### 0 件のコメント

サインイン to comment.

Translated by