1
+ function SPIROPAchl = importfile(workbookFile , sheetName , dataLines )
2
+ % IMPORTFILE Import data from a spreadsheet
3
+ % SPIROPACHL = IMPORTFILE(FILE) reads data from the first worksheet in
4
+ % the Microsoft Excel spreadsheet file named FILE. Returns the data as
5
+ % a table.
6
+ %
7
+ % SPIROPACHL = IMPORTFILE(FILE, SHEET) reads from the specified
8
+ % worksheet.
9
+ %
10
+ % SPIROPACHL = IMPORTFILE(FILE, SHEET, DATALINES) reads from the
11
+ % specified worksheet for the specified row interval(s). Specify
12
+ % DATALINES as a positive scalar integer or a N-by-2 array of positive
13
+ % scalar integers for dis-contiguous row intervals.
14
+ %
15
+ % Example:
16
+ % SPIROPAchl = importfile("\\sosiknas1\Lab_data\SPIROPA\CHL\SPIROPAchl.xlsx", "chl", [2, 3887]);
17
+ %
18
+ % See also READTABLE.
19
+ %
20
+ % Auto-generated by MATLAB on 01-Nov-2019 08:23:42
21
+
22
+ %% Input handling
23
+
24
+ % If no sheet is specified, read first sheet
25
+ if nargin == 1 || isempty(sheetName )
26
+ sheetName = 1 ;
27
+ end
28
+
29
+ % If row start and end points are not specified, define defaults
30
+ if nargin <= 2
31
+ dataLines = [2 , 3887 ];
32
+ end
33
+
34
+ %% Setup the Import Options
35
+ opts = spreadsheetImportOptions(" NumVariables" , 28 );
36
+
37
+ % Specify sheet and range
38
+ opts.Sheet = sheetName ;
39
+ opts.DataRange = " A" + dataLines(1 , 1 ) + " :AB" + dataLines(1 , 2 );
40
+
41
+ % Specify column names and types
42
+ opts.VariableNames = [" Cruise" , " Cast" , " Niskin" , " TargetDepth" , " Replicate" , " VolFilt" , " FilterSize" , " VolExtracted" , " Sample" , " Acetone" , " DilutionDuringReading" , " Chl_Cal_Filename" , " tau_Calibration" , " Fd_Calibration" , " Rb" , " Ra" , " blank" , " Rbblank" , " Rablank" , " Chlugl" , " Phaeougl" , " Cal_Date" , " Fluorometer" , " Labnotebookandpagenumber" , " Comments" , " quality_flag" , " Sample1" , " Acetone1" ];
43
+ opts.SelectedVariableNames = [" Cruise" , " Cast" , " Niskin" , " TargetDepth" , " Replicate" , " VolFilt" , " FilterSize" , " VolExtracted" , " Sample" , " Acetone" , " DilutionDuringReading" , " Chl_Cal_Filename" , " tau_Calibration" , " Fd_Calibration" , " Rb" , " Ra" , " blank" , " Rbblank" , " Rablank" , " Chlugl" , " Phaeougl" , " Cal_Date" , " Fluorometer" , " Labnotebookandpagenumber" , " Comments" , " quality_flag" , " Sample1" , " Acetone1" ];
44
+ opts.VariableTypes = [" categorical" , " double" , " double" , " double" , " categorical" , " double" , " double" , " double" , " double" , " double" , " double" , " categorical" , " double" , " double" , " double" , " double" , " double" , " double" , " double" , " double" , " double" , " datetime" , " string" , " categorical" , " categorical" , " double" , " double" , " double" ];
45
+ opts = setvaropts(opts , 22 , " InputFormat" , " " );
46
+ opts = setvaropts(opts , 23 , " WhitespaceRule" , " preserve" );
47
+ opts = setvaropts(opts , [1 , 5 , 12 , 23 , 24 , 25 ], " EmptyFieldRule" , " auto" );
48
+
49
+ % Import the data
50
+ SPIROPAchl = readtable(workbookFile , opts , " UseExcel" , false );
51
+
52
+ for idx = 2 : size(dataLines , 1 )
53
+ opts.DataRange = " A" + dataLines(idx , 1 ) + " :AB" + dataLines(idx , 2 );
54
+ tb = readtable(workbookFile , opts , " UseExcel" , false );
55
+ SPIROPAchl = [SPIROPAchl ; tb ]; % #ok<AGROW>
56
+ end
57
+
58
+ end
0 commit comments