MATLAB: Find index of cell array

cell arrays

Hello all, suppose i have cell array 6×1 which contains abstracts of articles, so each row of the cell contains 800 character. if i wan to find the position of str='b e h i n d' from that cell array,only b will be generated, so what is wrong my code. the cell arrays data is in the attachment or myabs.mat
load ('myabs.mat');
mydata=X;
[row,column]=size(mydata);
distance=zeros(row,column);
str='behind using a cover';
j=1;
for n=1:row
gec=char(mydata{n});
%for j=1:length(str)

for m=1:800
while j<length(str)
%for j=1:length(str)
if (gec(m)==str(j))
indexx(j)=m;
distance(n,m)=indexx(j);
end
break;
j=j+1;
end
end
end

Best Answer

There might be simpler ways to achieve this task, but this seems to work:
str = 'behind';
load myabs
for m = 1:numel(X)
Y = bsxfun(@eq,X{m}(:),str);
for n = 2:size(Y,2)
Y(:,n) = Y(:,n) & cumsum(Y(:,n-1))>0;
end
Z = find(any(diff([false(size(str));cumsum(Y)>0],1),2))
end
and when run it prints this in the command window:
Z =
135
149
235
236
239
266
Z =
72
73
127
136
160
174
Z =
163
170
172
173
177
221
Z =
40
53
65
66
76
112
Z =
216
217
267
279
295
319
Z =
170
175
178
196
197
234