hello experts...see I am executing a code....want some suggestions
Show older comments
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
Answers (1)
Walter Roberson
on 6 May 2015
0 votes
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 Comments
tina jain
on 7 May 2015
Walter Roberson
on 7 May 2015
Replace the line
if( count(i+1)==1 )
with
if false
Then in your test script after you have computed the compression ratio,
bytes_from_encoding = aaAA(1:2:end );
reversed_bytes = fliplr(bytes_from_encoding);
str_of_reversed_bytes = char(reversed_bytes);
tina jain
on 7 May 2015
Walter Roberson
on 7 May 2015
Please show
X
aaAA
str_of_reversed_bytes
Walter Roberson
on 8 May 2015
You did not use the same X as in your problem statement, so I cannot compare the result to what you had stated that you wanted.
Walter Roberson
on 8 May 2015
Those spaces are not really spaces. See http://uk.mathworks.com/matlabcentral/answers/215294#comment_283959
tina jain
on 9 May 2015
Categories
Find more on Signal Processing Toolbox 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!