loop on a strfind

5 ビュー (過去 30 日間)
Mate 2u
Mate 2u 2012 年 7 月 6 日
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.

回答 (1 件)

Jonathan Sullivan
Jonathan Sullivan 2012 年 7 月 6 日
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);


Help Center および File ExchangeCharacters and Strings についてさらに検索


Community Treasure Hunt

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

Start Hunting!

Translated by