4.0

4.0 | 1 rating Rate this file 4 Downloads (last 30 days) File Size: 2.24 KB File ID: #6575

phrase2word.m

by Stefan Billig

 

20 Dec 2004 (Updated 04 Jan 2005)

String separation - useful for ASCII data header lines

| Watch this File

File Information
Description

%-------------------------------------------------------------
% out=phrase2word(phrase, <delimiter,token>) | Version 1.1
%-------------------------------------------------------------
% Cuts input phrase separated by delimiter into words.
% Consecutive delimiters are recognized and the "missing"
% words inbetween are marked by default with a whitespace.
% Useful to extract data labels from a csv-header line.
%-------------------------------------------------------------
% Example:
% words = phrase2word('time,data')
%
% results in {'time','data'}
% By default, ',' is chosen as delimiter, thus
%
% words = phrase2word('time,data',',')
%
% has the same result.
%
% words = phrase2word('time,,data',',','*')
%
% gives {'time' '*' 'data'} with "*" marking empty word.
%-------------------------------------------------------------
% Start: 2003-08-11, S. Billig | Last Change: 2004-11-30, SB
%-------------------------------------------------------------
% has the same result as above.

MATLAB release MATLAB 6.5 (R13)
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (1)
29 Sep 2005 Thomas McNeill

I found this program very useful but....

Problem exists if last character of input string is a delimiter.
Error Message:
   ??? Index exceeds matrix dimensions.
Error in ==> L:\IntShared\MatLabScripts\phrase2word.m
On line 58 ==> if isequal(rem(1),delim) & isequal(rem(1),rem(2))

% add lines below to fix error
[a,b] = size(inVar); % determine size of input string variable
if isequal(inVar(a,b),delim) % Check if last character is same as delim
    inVar(a,b+1)=' ' % if so then add space character to end
end

Please login to add a comment or rating.
Updates
04 Jan 2005

Ver. 1.1 gives more flexibility for replacing missing words.
Bugfix for several occurrences of the same word in the phrase...

Tag Activity for this File
Tag Applied By Date/Time
strings Stefan Billig 22 Oct 2008 07:38:27
split Stefan Billig 22 Oct 2008 07:38:27
string Stefan Billig 22 Oct 2008 07:38:27
header Stefan Billig 22 Oct 2008 07:38:27
utilities Stefan Billig 22 Oct 2008 07:38:27
string manipulation Stefan Billig 22 Oct 2008 07:38:27

Contact us at files@mathworks.com