I have few questions regarding string. I have applied Run Length Encoding on a large string. But at the output I am getting some unwanted symbols. why it is so?
1 view (last 30 days)
Show older comments
function y = estring(str)
len = numel(str); %65536
i = 0;
count = zeros(1,len);
y=[];
while( i<len )
j=0;
count(i+1) = 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 false
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;
if(count==1)
y=[y a b]
end
end
end
1 Comment
Answers (1)
Walter Roberson
on 12 May 2015
I already answered this in a previous discussion. Every second character of your returned string is the char() equivalent of a binary count. Remember, if you have ['P' 9] the result is not 'P9', it is 'P' followed by char(9) which happens to be the tab character. If you want to have 'P9' as the result when the count is 9 then you need to program the code that way and you need to decide exactly what you want to have happen if you get more than 9 in a row of the same thing.
See Also
Categories
Find more on Characters and Strings 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!