meaning in matlab help example of textread " Read Using Literal to Ignore Matching Characters"

1 view (last 30 days)
I don't understand a script on matlab help file of 'textread', example 4, about data = textread('data.csv', '', 'delimiter', ',','emptyvalue', NaN); what is the scripts to remove the comma ',' from the original data, and I have seen a scripts that ignore the head text by using 'headerlines', 15,how does this work?
the original example is For files with empty cells, use the emptyvalue parameter. Suppose the file data.csv contains:1,2,3,4,,6 7,8,9,,11,12Read the file using NaN to fill any empty cells:data = textread('data.csv', '', 'delimiter', ',', ... 'emptyvalue', NaN);

Accepted Answer

dpb
dpb on 16 Apr 2014
Data file contains
1,2,3,4,,6
7,8,9,,11,1
Note there are two consecutive commas between 4 and 6 in first row and again between 9 and 11 in second. That implies a missing piece of data that would otherwise be expected in that location --iow, a piece of "missing (or empty) data". The 'emptyvalue' parameter just substitutes the value given for its value in that location when reading the file. There is no "removing the comma from the original data".
As for 'headerlines',N, it skips that many lines as given by the value of N at the beginning of the file before processing anything. Useful for such things as spreadsheets, etc., that have a column of variable names or the like at the beginning before the data.
  2 Comments
Miao
Miao on 16 Apr 2014
Thank u very much. I got it, I still want to ask what does " '', 'delimiter', ',',"mean, it seems to find empty places,and is 'delimiter' here means fingding the comma?
dpb
dpb on 16 Apr 2014
Edited: dpb on 16 Apr 2014
delimiter
A delimiter is a sequence of one or more characters used to specify the boundary between separate, independent regions in plain text or other data streams. An example of a delimiter is the comma character, which acts as a field delimiter in a sequence of comma-separated values.
Per the definition, a delimiter is the character used to separate fields in a delimiter-separated file. The comma could be a space or a semi-colon or tab; it would still be the delimiter.
In textread or textscan and friends, the 'delimiter' property is simply the way to specify the specific delimiter character for a given file. In this case it was/is the comma; in other cases it could be something else.
So, yes, indirectly it means "finding the comma" because when there's a delimiter character in the file as defined, the job of the input functions is to demarcate (separate) fields based on that particular character.

Sign in to comment.

More Answers (0)

Categories

Find more on Characters and Strings in Help Center and File Exchange

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!