divide chain code to sub chain code

2 visualizaciones (últimos 30 días)
majed majed
majed majed el 9 de Feb. de 2016
Comentada: majed majed el 15 de Feb. de 2016
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.

Respuestas (1)

Geoff Hayes
Geoff Hayes el 10 de Feb. de 2016
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 comentario
majed majed
majed majed el 15 de Feb. de 2016
thank you for answering .. this code is as same as what i have written . i still wondering if i can improve it. thank you

Iniciar sesión para comentar.

Categorías

Más información sobre Mathematics en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by