time | Calls | line |
---|
| | 75 | function [var,errid,placeholder] = readTextSpreadsheetVariable(varopts,sheet,subrange,typeIDs)
|
| | 76 | % Construct a placeholder var based on datatype - string or char
|
< 0.001 | 8 | 77 | if strcmp(varopts.Type, 'string')
|
| | 78 | var = strings(size(typeIDs));
|
< 0.001 | 8 | 79 | else
|
0.002 | 8 | 80 | var = repmat({''},size(typeIDs));
|
< 0.001 | 8 | 81 | end
|
| | 82 |
|
| | 83 | % Initialize errid + placeholder logical vector
|
< 0.001 | 8 | 84 | errid = false(size(typeIDs));
|
< 0.001 | 8 | 85 | placeholder = errid;
|
| | 86 |
|
| | 87 | % If varopts is not a struct, convert to a struct
|
< 0.001 | 8 | 88 | if ~(isstruct(varopts))
|
0.004 | 5 | 89 | varopts = getOptsStruct(varopts);
|
< 0.001 | 8 | 90 | end
|
| | 91 |
|
< 0.001 | 8 | 92 | textmask = typeIDs == sheet.STRING;
|
< 0.001 | 8 | 93 | if any(textmask,'all')
|
0.001 | 8 | 94 | data = sheet.readStrings(subrange);
|
| | 95 |
|
| | 96 | % Operate columnwise
|
< 0.001 | 8 | 97 | for i = 1:size(data,2)
|
< 0.001 | 17 | 98 | textmaskInd = textmask(:,i);
|
< 0.001 | 17 | 99 | [textData, errData, placeholdermask] = matlab.io.internal.text.datatypeConvertFromString(varopts,data(textmaskInd,i));
|
| | 100 |
|
< 0.001 | 17 | 101 | placeholder(textmaskInd,i) = placeholdermask;
|
< 0.001 | 17 | 102 | errid(textmaskInd,i) = errData;
|
< 0.001 | 17 | 103 | var(textmaskInd,i) = textData;
|
< 0.001 | 17 | 104 | end
|
| | 105 | else
|
| | 106 | placeholder = false(size(typeIDs));
|
< 0.001 | 8 | 107 | end
|
| | 108 |
|
< 0.001 | 8 | 109 | datemask = typeIDs == sheet.DATETIME;
|
< 0.001 | 8 | 110 | if any(datemask,'all')
|
| | 111 | complexRepDates = sheet.readDates(subrange);
|
| | 112 | dates = matlab.io.spreadsheet.internal.createDatetime(complexRepDates(datemask), 'default', '');
|
| | 113 | var(datemask) = cellstr(dates, [], 'system');
|
< 0.001 | 8 | 114 | end
|
| | 115 |
|
< 0.001 | 8 | 116 | boolmask = typeIDs == sheet.BOOLEAN;
|
< 0.001 | 8 | 117 | if any(boolmask,'all')
|
| | 118 | % Convert to 'true' and 'false'
|
| | 119 | values = {'true'; 'false'};
|
| | 120 | data = sheet.readBooleans(subrange);
|
| | 121 | var(boolmask) = values(2 - data(boolmask),:);
|
< 0.001 | 8 | 122 | end
|
| | 123 |
|
< 0.001 | 8 | 124 | numbermask = typeIDs == sheet.NUMBER;
|
< 0.001 | 8 | 125 | if any(numbermask,'all')
|
| | 126 | data = sheet.readNumbers(subrange);
|
| | 127 | data(~numbermask) = [];
|
| | 128 | strdata = num2str(data(:));
|
| | 129 | var(numbermask) = strtrim(cellstr(strdata));
|
< 0.001 | 8 | 130 | end
|
< 0.001 | 8 | 131 | end
|
Other subfunctions in this file are not included in this listing.