hello experts...see I am executing a code....want some suggestions

조회 수: 1 (최근 30일)
tina jain
tina jain 2015년 5월 6일
댓글: tina jain 2015년 5월 9일
My code is
%script----------------------------------%
X= ' PPtPPPPP';
lengh=numel(X);
aaAA=estring(X);
zz=numel(aaAA);
comp_ratio=(lengh)/(zz)
%------------------------------------------
function y = estring(str)
len = numel(str);
i = 0;
count = zeros(1,len);
y=[];
while( i<len )
j=0;
count(i+1) = 1;
if(count==1)
y=[y 1];
while( true )
j = j + 1;
if( i+j+1 > len )
break;
end
if( str(i+j+1)==str(i+1) )
count(i+1) = count(i+1) + 1;
else
break;
end
end
if( count(i+1)==1 )
a=str(i+1);
length(a);
y = [y a];
i = i + 1;
else
a=str(i+1);
b=count(i+1);
y =[y a b];
i = i + b;
end
end
end
Input: PPtPPPPP
numel(Input)=8
*Output :* P tP [space at the end]
numel(Output)=5
I want this to be like Output" P t P [space] numel(output)=4
Please help me to modify the code to consider single count as character plus space

답변 (1개)

Walter Roberson
Walter Roberson 2015년 5월 6일
To achieve that output:
  • do not do anything special for count 1: treat it like all of the others
  • Output = fliplr( aaAA(1:2:end) )
  댓글 수: 8
tina jain
tina jain 2015년 5월 9일
done with this....but I want to know further....in some situations it is giving compression ratio up to 100...is it OK?

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

카테고리

Help CenterFile Exchange에서 String Parsing에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by