필터 지우기
필터 지우기

Generate all possible subset from a character array in MATLAB

조회 수: 2 (최근 30일)
Sangeetha R
Sangeetha R 2019년 3월 30일
답변: Walter Roberson 2019년 3월 30일
I need to generate all possible subset from a character array with reduced execution time. Actual input is of length '500' characters and maximum length of subset is limited to 20 characters.
For example:
input='ABCA';
output ='A', 'B', 'C', 'AB', 'BC', 'CA', 'ABC', 'BCA', 'ABCA'
  댓글 수: 4
Walter Roberson
Walter Roberson 2019년 3월 30일
Could you confirm that length(unique(input)) is 500? For example 500 Chinese ideographs? As opposed to length(input) being 500 but the number of unique being much smaller?
Sangeetha R
Sangeetha R 2019년 3월 30일
length(input) is 500

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

답변 (2개)

Sangeetha R
Sangeetha R 2019년 3월 30일
편집: Sangeetha R 2019년 3월 30일
Answer that i found is given below,
tic
input='MERASLIQKAKLAEQAERYEDMAAFMKGAVEKGEELSCEERNLLSVAYKNVVGGQRAAWRVLSSIEQKSNEEGSEEKGPEVREYRVFYLKMKGDYYRYLAEVATGDDKKRIIDSARSAYQEAMDISKKEMPPTNPIRLGLALNFSVFHYEIANSPEEAISLAKTTFDEAMADLHTLSEDSYKDSTLIMQLLRDNLTLWTADNAGEEGGEAPQEPQSMERASLIQKAKLAEQAERYEDMAAFMKGAVEKGEELSCEERNLLSVAYKNVVGGQRAAWRVLSSIEQKSNEEGSEEKGPEVREYRVFYLKMKGDYYRYLAEVATGDDKKRIIDSARSAYQEAMDISKKEMPPTNPIRLGLALNFSVFHYEIANSPEEAISLAKTTFDEAMADLHTLSEDSYKDSTLIMQLLRDNLTLWTADNAGEEGGEAPQEPQSSEDSYKDSTLIMQLLRDNLTLWTADNAGEEGGEAPQEPQSMERASLIQKAKLAEQAERYEDMAAFMKGAVEKGEELSCEERNLLSVAYKNVVGGQRAAW';
l=length(input);
begn=1;
count=1;
output_seq=cell(1000,1);%preallocating
for i=1:l
if(begn<=l)
[count,output_seq]=pep(begn,l,input,count,output_seq);
begn=begn+1;
end
end
output_unique=unique(output_seq);
toc
function [count,output_seq]=pep(b,l,input,count,output_seq)
for i=0:l
if(b+i-b<21)
if(b+i<=l)
p = input(b:b+i);
output_seq{count}=p;
count=count+1;
end
end
end
end

Walter Roberson
Walter Roberson 2019년 3월 30일
Consider
[S(1:end-2);
S(2:end-1);
S(3:end)].'
Now unique rows

카테고리

Help CenterFile Exchange에서 C Shared Library Integration에 대해 자세히 알아보기

태그

제품


릴리스

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by