What part are you not able to make more versatile?
If you know a priori the number of columns, you can make the following changes
function data = Load_Data( filename, strain_command_data, nCol )
if nargin < 3
nCol = 5 ;
end
formatSpec = repmat( '%f', 1, nCol ) ;
FID = fopen( filename ) ;
data = textscan( FID, formatSpec, 'HeaderLines', 5, 'CollectOutput', 1 ) ;
.. etc.
end
If you don't know a priori the number of lines, you could determine it based on one line of the header. If the file had the following content
Header line 1..
Header line 2..
dataID time x y
1 120 8.7 9.1
you could determine that there are 4 columns based on the 3rd line of the header which contains column labels..
function data = Load_Data( filename, strain_command_data )
fid = fopen( filename, 'r' ) ;
fgetl( fid ) ;
fgetl( fid ) ;
colLabels = fgetl( fid ) ;
nCol = numel( regexp( colLabels, '\s+' )) + 1 ;
formatSpec = repmat( '%f', 1, nCol ) ;
data = textscan( fid, formatSpec, 'CollectOutput', 1 ) ;
.. etc.
end
Best Answer