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.
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.
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.