loop on a strfind

6 views (last 30 days)
Mate 2u
Mate 2u on 6 Jul 2012
Hi all, I have a loop as such:
parfor i =1:1000000
ZZ= strfind(A2,lm(i,:));
now this lm is fine it's a set of strings of size 10 (many of them). And A2 is a large string.
I need to modify this...I have another string B2.
I need to do it so that at the first iteration the strfind looks in A2, then in the second iteration (i=2) then it looks in [A2 B2(1)], then on third iteration it looks in [A2 B2(2)] etc....
If anybody needs clarification I will rewrite question. Thank you.

Answers (1)

Jonathan Sullivan
Jonathan Sullivan on 6 Jul 2012
I think this can be done with arrayfun.
% Your inputs
A2 = 'Number';
B2 = '0123456789';
lm = char(randi([32 64],10,100));
% Make the thing strings you want to find
ABz = strcat(A2,B2(:));
% Find them
out = arrayfun(@(ind) strfind(ABz{ind,:},lm(ind2,:)).1:length(ABz),'uni',false);


Community Treasure Hunt

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

Start Hunting!