Be the first to rate this file! 15 downloads (last 30 days) File Size: 1.46 KB File ID: #26616

stringCollapser

by Avinash Rude

 

07 Feb 2010

Code covered by the BSD License  

Collapses a long comma separated string using a counter for repeated sub-strings

Download Now | Watch this File

File Information
Description

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.

MATLAB release MATLAB 7.8 (R2009a)
Zip File Content  
Other Files license.txt,
strCollapser.m
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (3)
12 Feb 2010 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.

16 Feb 2010 Avinash Rude

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.

17 Feb 2010 Oleg Komarov

help tic % for time calculation

preallocation:
http://www.mathworks.com/access/helpdesk/help/techdoc/matlab_prog/f8-784135.html#f8-793781

Regards

Please login to add a comment or rating.
Tag Activity for this File
Tag Applied By Date/Time
string collapse Avinash Rude 08 Feb 2010 12:14:10
string manipulation Avinash Rude 08 Feb 2010 12:14:10
number string Avinash Rude 08 Feb 2010 12:14:10
count strings Avinash Rude 08 Feb 2010 12:14:10
strings Avinash Rude 08 Feb 2010 12:14:10
signal processing Avinash Rude 08 Feb 2010 12:14:10
timeseries Avinash Rude 08 Feb 2010 12:14:10
tags Avinash Rude 08 Feb 2010 12:14:10
abstraction Avinash Rude 08 Feb 2010 12:14:10
grammar Avinash Rude 08 Feb 2010 12:14:10
 

MATLAB Central Terms of Use

NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Terms prior to use.

Contact us at files@mathworks.com