SCM Repository

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

View of /SplineFitBATMAN_MATLABcode/read_mixed_csv.m

Parent Directory Parent Directory | Revision Log Revision Log

Revision 346 - (download) (annotate)
Tue Nov 11 03:01:17 2014 UTC (2 years, 4 months ago) by jie
File size: 1276 byte(s)
function lineArray = read_mixed_csv(fileName,delimiter)
%  modified by Dr. Jie Hao, Imperial College London 
fid = fopen(fileName,'r');   %# Open the file
lineArray = cell(100,1);     %# Preallocate a cell array (ideally slightly
%#   larger than is needed)
lineIndex = 1;               %# Index of cell to place the next line in
nextLine = fgetl(fid);       %# Read the first line from the file
while ~isequal(nextLine,-1)         %# Loop while not at the end of the file
    lineArray{lineIndex} = nextLine;  %# Add the line to the cell array
    lineIndex = lineIndex+1;          %# Increment the line index
    nextLine = fgetl(fid);            %# Read the next line from the file
fclose(fid);                 %# Close the file
lineArray = lineArray(1:lineIndex-1);  %# Remove empty cells, if needed
for iLine = 1:lineIndex-1              %# Loop over lines
    lineData = textscan(lineArray{iLine},'%q',...  %# Read strings
    lineData = lineData{1};              %# Remove cell encapsulation
    if strcmp(lineArray{iLine}(end),delimiter)  %# Account for when the line
        lineData{end+1} = '';                     %#   ends with a delimiter
    lineArray(iLine,1:numel(lineData)) = lineData;  %# Overwrite line data
ViewVC Help
Powered by ViewVC 1.0.0  
Thanks to:
Vienna University of Economics and Business University of Wisconsin - Madison Powered By FusionForge