divide chain code to sub chain code
3 次查看(过去 30 天)
显示 更早的评论
I want to write a function which divide chain code with n elements into m sub chain code where the first sub chain code just contains the first two elements of chain code a with iterations , the second sub chain code contains the next two elements with iterations. For example if we have chain code a a=455454545444544444445444444445444444544444445444444444444444434444343223
I want to divide it into three sub chain code :
a1=4554545454445444444454444444454444445444444454444444444444444
a2=34444343
a2=223
i have written a function for this goals but with low time proficiency . thank you for any answer.
0 个评论
回答(1 个)
Geoff Hayes
2016-2-10
majed - I'm not sure if this is more efficient than what you have, but it does produce the answer that you are looking for (assuming the the input chain is a string).
chain='455454545444544444445444444445444444544444445444444444444444434444343223';
setOf2 = chain(1);
startIndex = 1;
subchains = {};
for k=2:length(chain)
if ismember(chain(k),setOf2)
continue;
else
if length(setOf2) == 1
setOf2 = [setOf2 ; chain(k)];
else
subchains = [subchains chain(startIndex:k-1)];
startIndex = k;
setOf2 = chain(k);
end
end
end
subchains = [subchains chain(startIndex:end)];
subchains = [subchains chain(strtIdx:end)];
setOf2 is an array of the two distinct elements that are allowed in the subchain. We iterate over each member of the chain and check to see if it is a member of (contained within) the setOf2. If yes, then we continue to the next element. If not, then we have encountered a third unique element and so have completed the a subchain (which is added to the subchains cell array) and start a new one.
Try the above and see what happens!
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Testing Frameworks 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!