File Exchange

image thumbnail

stringCollapser

version 1.0.0.0 (1.46 KB) by Avinash Rude
Collapses a long comma separated string using a counter for repeated sub-strings

0 Downloads

Updated 07 Feb 2010

View License

Example 1-
Input string = 'abc,abc,abc,dcf,dcf,ef'.
output string ='3abc,2dcf,1ef'

Example 2-
Input string = 'xyzr,abdc,abdc,haha,haha'.
output string ='1xyzr,2abdc,2haha'

Explanation:
This function collapses a comma separated long string, containing sub-strings, into a possibly smaller string by replacing repeated sub-strings by counts of repetitions of substrings.

Cite As

Avinash Rude (2020). stringCollapser (https://www.mathworks.com/matlabcentral/fileexchange/26616-stringcollapser), MATLAB Central File Exchange. Retrieved .

Comments and Ratings (3)

Oleg Komarov:

First, Thanks for the careful scrutiny of my code. I will address some of your points further:

>>Unmeaningful H1 line, poor help but at least the example is easy to understand. Author, contact and creation date are shown but there is no need to include those info in the help block.

Okay, will correct that.

>> I'm not against loops but you should really learn preallocation:
% A: 0.610 MB
A = repmat(',abc,abc,abc,ghf,ghf,der,der,dfg',1,10000);

Thanks for this preallocation tip.

>>tic
OUT = strCollapser(A);
toc
>> % Elapsed time is 60.312876 seconds.

How did you calculate the time? Let me know.

>>Completely useless the last line of code:
%str;
%strParsed;
str1;

Opps! Should've deleted that... It is a remnant while the fuction was written.

>>No comments in the body.

Will include them.

>>I can't think of any use for this fcn, the output again is too complex and unmanageable.

True, that it gives an unmanageable string. However, it served my purpose of collapsing a very long string with repeated substrings.

Oleg Komarov

Unmeaningful H1 line, poor help but at least the example is easy to understand. Author, contact and creation date are shown but there is no need to include those info in the help block.

I'm not against loops but you should really learn preallocation:
% A: 0.610 MB
A = repmat(',abc,abc,abc,ghf,ghf,der,der,dfg',1,10000);

tic
OUT = strCollapser(A);
toc
% Elapsed time is 60.312876 seconds.

% Matrix indexing is a useful chapter of online documentation
str(length(str))~=',' where length(str) can be replaced with end

Completely useless the last line of code:
%str;
%strParsed;
str1;

No comments in the body.

I can't think of any use for this fcn, the output again is too complex and unmanageable.

MATLAB Release Compatibility
Created with R2009a
Compatible with any release
Platform Compatibility
Windows macOS Linux