how to find subsequences

3 views (last 30 days)
pamela sulis
pamela sulis on 4 Apr 2016
Answered: Azzi Abdelmalek on 4 Apr 2016
Hi! I have
a={'1' '631' '618' '574' '678'}
and I want to find all possible sequences:
{'1'}
{'1' '631'}
{'1' '631' '618'}
{'1' '631' '618' '574'}
{'1' '631' '618' '574' '678'}
{'631'}
{'631' '618'}
{'631' '618' '574'}
{'631' '618' '574' '678'}
{'618'}
{'618' '574'}
{'618' '574' '678'}
{'574'}
{'574' '678'}
{'678'}
how can I do? thanks

Accepted Answer

Azzi Abdelmalek
Azzi Abdelmalek on 4 Apr 2016
a={'1' '631' '618' '574' '678'}
n=numel(a)
for k=1:n
b{k}=arrayfun(@(x) k:x,k:n,'un',0)
end
c=[b{:}]'
out=cellfun(@(x) a(x),c,'un',0)
out{1}
out{2}
out{3}

More Answers (0)

Categories

Find more on Data Types in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!