divide chain code to sub chain code

조회 수: 3 (최근 30일)
majed majed
majed majed 2016년 2월 9일
댓글: majed majed 2016년 2월 15일
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.

답변 (1개)

Geoff Hayes
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!
  댓글 수: 1
majed majed
majed majed 2016년 2월 15일
thank you for answering .. this code is as same as what i have written . i still wondering if i can improve it. thank you

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Testing Frameworks에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by