SCM

SCM Repository

[batman] Annotation of /SplineFitBATMAN_MATLABcode/read_mixed_csv.m
ViewVC logotype

Annotation of /SplineFitBATMAN_MATLABcode/read_mixed_csv.m

Parent Directory Parent Directory | Revision Log Revision Log


Revision 346 - (view) (download)

1 : jie 346 function lineArray = read_mixed_csv(fileName,delimiter)
2 :     % modified by Dr. Jie Hao, Imperial College London
3 :     fid = fopen(fileName,'r'); %# Open the file
4 :     lineArray = cell(100,1); %# Preallocate a cell array (ideally slightly
5 :     %# larger than is needed)
6 :     lineIndex = 1; %# Index of cell to place the next line in
7 :     nextLine = fgetl(fid); %# Read the first line from the file
8 :     while ~isequal(nextLine,-1) %# Loop while not at the end of the file
9 :     lineArray{lineIndex} = nextLine; %# Add the line to the cell array
10 :     lineIndex = lineIndex+1; %# Increment the line index
11 :     nextLine = fgetl(fid); %# Read the next line from the file
12 :     end
13 :     fclose(fid); %# Close the file
14 :     lineArray = lineArray(1:lineIndex-1); %# Remove empty cells, if needed
15 :     for iLine = 1:lineIndex-1 %# Loop over lines
16 :     lineData = textscan(lineArray{iLine},'%q',... %# Read strings
17 :     'Delimiter',delimiter);
18 :     lineData = lineData{1}; %# Remove cell encapsulation
19 :     if strcmp(lineArray{iLine}(end),delimiter) %# Account for when the line
20 :     lineData{end+1} = ''; %# ends with a delimiter
21 :     end
22 :     lineArray(iLine,1:numel(lineData)) = lineData; %# Overwrite line data
23 :     end

R-Forge@R-project.org
ViewVC Help
Powered by ViewVC 1.0.0  
Thanks to:
Vienna University of Economics and Business University of Wisconsin - Madison Powered By FusionForge