Home > Angelas_Raster_Code > import_caldatafile.m

import_caldatafile

PURPOSE ^

IMPORTFILE Import numeric data from a text file as column vectors.

SYNOPSIS ^

function VarName1 = import_caldatafile(filename, startRow, endRow)

DESCRIPTION ^

IMPORTFILE Import numeric data from a text file as column vectors.
   VARNAME1 = IMPORTFILE(FILENAME) Reads data from text file FILENAME for
   the default selection.

   VARNAME1 = IMPORTFILE(FILENAME, STARTROW, ENDROW) Reads data from rows
   STARTROW through ENDROW of text file FILENAME.

 Example:
   VarName1 = importfile('caldata_files.txt',1, 13);

    See also TEXTSCAN.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function VarName1 = import_caldatafile(filename, startRow, endRow)
0002 %IMPORTFILE Import numeric data from a text file as column vectors.
0003 %   VARNAME1 = IMPORTFILE(FILENAME) Reads data from text file FILENAME for
0004 %   the default selection.
0005 %
0006 %   VARNAME1 = IMPORTFILE(FILENAME, STARTROW, ENDROW) Reads data from rows
0007 %   STARTROW through ENDROW of text file FILENAME.
0008 %
0009 % Example:
0010 %   VarName1 = importfile('caldata_files.txt',1, 13);
0011 %
0012 %    See also TEXTSCAN.
0013 
0014 % Auto-generated by MATLAB on 2014/03/19 10:50:07
0015 
0016 %% Initialize variables.
0017 delimiter = '';
0018 if nargin<=2
0019     startRow = 1;
0020     endRow = inf;
0021 end
0022 
0023 %% Format string for each line of text:
0024 %   column1: text (%s)
0025 % For more information, see the TEXTSCAN documentation.
0026 formatSpec = '%s%[^\n\r]';
0027 
0028 %% Open the text file.
0029 fileID = fopen(filename,'r');
0030 
0031 %% Read columns of data according to format string.
0032 % This call is based on the structure of the file used to generate this
0033 % code. If an error occurs for a different file, try regenerating the code
0034 % from the Import Tool.
0035 dataArray = textscan(fileID, formatSpec, endRow(1)-startRow(1)+1, 'Delimiter', delimiter, 'HeaderLines', startRow(1)-1, 'ReturnOnError', false);
0036 for block=2:length(startRow)
0037     frewind(fileID);
0038     dataArrayBlock = textscan(fileID, formatSpec, endRow(block)-startRow(block)+1, 'Delimiter', delimiter, 'HeaderLines', startRow(block)-1, 'ReturnOnError', false);
0039     dataArray{1} = [dataArray{1};dataArrayBlock{1}];
0040 end
0041 
0042 %% Close the text file.
0043 fclose(fileID);
0044 
0045 %% Post processing for unimportable data.
0046 % No unimportable data rules were applied during the import, so no post
0047 % processing code is included. To generate code which works for
0048 % unimportable data, select unimportable cells in a file and regenerate the
0049 % script.
0050 
0051 %% Allocate imported array to column variable names
0052 VarName1 = dataArray{:, 1};
0053

Generated on Sun 14-Jun-2015 17:12:45 by m2html © 2005