-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathimportSummaryFile.m
More file actions
66 lines (56 loc) · 2.19 KB
/
Copy pathimportSummaryFile.m
File metadata and controls
66 lines (56 loc) · 2.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
function tableout = importSummaryFile(workbookFile,sheetName,startRow,endRow)
%importSummaryFile Import data from a spreadsheet
% DATA = importSummaryFile(FILE) reads data from the first worksheet in the
% Microsoft Excel spreadsheet file named FILE and returns the data as a
% table.
%
% DATA = importSummaryFile(FILE,SHEET) reads from the specified worksheet.
%
% DATA = importSummaryFile(FILE,SHEET,STARTROW,ENDROW) reads from the specified
% worksheet for the specified row interval(s). Specify STARTROW and
% ENDROW as a pair of scalars or vectors of matching size for
% dis-contiguous row intervals. To read to the end of the file specify an
% ENDROW of inf.
%
% Non-numeric cells are replaced with: NaN
%
% Example:
% SubImageS2 = importSummaryFile('SubImage.xlsx','GoogLe13',2,5185);
%
% See also XLSREAD.
% Auto-generated by MATLAB on 2018/07/24 15:05:40
%% Input handling
% If no sheet is specified, read first sheet
if nargin == 1 || isempty(sheetName)
sheetName = 1;
end
% If row start and end points are not specified, define defaults
if nargin <= 3
startRow = 2;
endRow = 5185;
end
%% Import the data
[~, ~, raw] = xlsread(workbookFile, sheetName, sprintf('A%d:E%d',startRow(1),endRow(1)));
for block=2:length(startRow)
[~, ~, tmpRawBlock] = xlsread(workbookFile, sheetName, sprintf('A%d:E%d',startRow(block),endRow(block)));
raw = [raw;tmpRawBlock]; %#ok<AGROW>
end
raw(cellfun(@(x) ~isempty(x) && isnumeric(x) && isnan(x),raw)) = {''};
stringVectors = string(raw(:,[1,2]));
stringVectors(ismissing(stringVectors)) = '';
raw = raw(:,[3,4,5]);
%% Replace non-numeric cells with NaN
R = cellfun(@(x) ~isnumeric(x) && ~islogical(x),raw); % Find non-numeric cells
raw(R) = {NaN}; % Replace non-numeric cells
%% Create output variable
I = cellfun(@(x) ischar(x), raw);
raw(I) = {NaN};
data = reshape([raw{:}],size(raw));
%% Create table
tableout = table;
%% Allocate imported array to column variable names
tableout.File = stringVectors(:,1);
tableout.Category = categorical(stringVectors(:,2),{'Uncategorized','NotASample','OutOfFocus','None','Low','Moderate','High','Infection'},'Ordinal',true);
tableout.Score = data(:,1);
tableout.row = data(:,2);
tableout.col = data(:,3);