time | Calls | line |
---|
| | 55 | function obj = setTypes(obj,idx,newType,isHexBin)
|
| | 56 | % Extract the property while editing, since the is a handle
|
| | 57 | % object and validation can error based on type.
|
< 0.001 | 4 | 58 | if ~exist('isHexBin','var')
|
< 0.001 | 4 | 59 | isHexBin = false;
|
< 0.001 | 4 | 60 | end
|
< 0.001 | 4 | 61 | if (isempty(idx) && isempty(newType))
|
< 0.001 | 2 | 62 | return;
|
< 0.001 | 2 | 63 | end
|
| | 64 |
|
< 0.001 | 2 | 65 | newType = convertCharsToStrings(newType(:));
|
< 0.001 | 2 | 66 | if ~isstring(newType)
|
| | 67 | error(message('MATLAB:textio:textio:InvalidStringOrCellStringProperty','VariableTypes'));
|
< 0.001 | 2 | 68 | end
|
| | 69 |
|
< 0.001 | 2 | 70 | C = obj.OptionsStruct.Options;
|
| | 71 |
|
< 0.001 | 2 | 72 | t = matlab.io.internal.supportedTypeNames();
|
< 0.001 | 2 | 73 | if (isHexBin)
|
| | 74 | t{end + 1} = 'hexadecimal';
|
| | 75 | t{end + 1} = 'binary';
|
| 2 | 76 | end
|
< 0.001 | 2 | 77 | t{end + 1} = 'auto';
|
0.017 | 2 | 78 | tf = ismember(newType,t);
|
< 0.001 | 2 | 79 | if ~all(tf)
|
| | 80 | error(message('MATLAB:textio:io:UnsupportedConversionType',newType{find(~tf,1)}));
|
< 0.001 | 2 | 81 | end
|
| | 82 |
|
< 0.001 | 2 | 83 | if isstring(newType) && isscalar(newType)
|
| | 84 | newType = repmat(newType, numel(idx), 1);
|
< 0.001 | 2 | 85 | end
|
| | 86 | % Don't update the types or bother checking if the new type is
|
| | 87 | % the old type.
|
< 0.001 | 2 | 88 | oldTypes = obj.OptionsStruct.Types;
|
< 0.001 | 2 | 89 | typeChanged = (newType ~= oldTypes(idx));
|
< 0.001 | 2 | 90 | for ii = 1:numel(idx)
|
< 0.001 | 6 | 91 | kk = idx(ii);
|
< 0.001 | 6 | 92 | if typeChanged(ii)
|
| | 93 | % Type can change, need to validate the mismatched
|
| | 94 | % properties are removed.
|
< 0.001 | 3 | 95 | for f = fieldnames(C{kk})'
|
| | 96 | if strcmp(f,'InputFormat')
|
| | 97 | % datetime to duration change, this means
|
| | 98 | % InputFormat needs to be removed since there's
|
| | 99 | % no overlap between the two
|
| | 100 | C{kk} = rmfield(C{kk},'InputFormat');
|
| | 101 | elseif strcmp(f,'FillValue')
|
| | 102 | % Fillvalues can change when type changes,
|
| | 103 | % sometimes that "just works" and we can keep
|
| | 104 | % the old value, other times that may fail.
|
| | 105 |
|
| | 106 | if ~isCompatibleTypes(newType(ii),oldTypes(kk))
|
| | 107 | C{kk} = rmfield(C{kk},'FillValue');
|
| | 108 | end
|
| | 109 | else
|
| | 110 | if(f == "NumberSystem" && any(fieldnames(C{kk}) == "Type"))
|
| | 111 | C{kk}.Type= newType{ii};
|
| | 112 | end
|
| | 113 | % If the property doesn't exist on the new
|
| | 114 | % type, just drop it.
|
| | 115 | try
|
| | 116 | checkTypeSpecific(newType{ii},f)
|
| | 117 | catch
|
| | 118 | C{kk} = rmfield(C{kk},f);
|
| | 119 | if(f == "NumberSystem" && any(fieldnames(C{kk}) == "Type"))
|
| | 120 | C{kk} = rmfield(C{kk},'Type');
|
| | 121 | end
|
| | 122 | end
|
| | 123 | end
|
| | 124 | end
|
< 0.001 | 6 | 125 | end
|
< 0.001 | 6 | 126 | end
|
< 0.001 | 2 | 127 | obj.OptionsStruct.Options = C;
|
< 0.001 | 2 | 128 | obj.OptionsStruct.Types(idx) = cellstr(newType);
|
| | 129 |
|
| | 130 | % if it was already uniform and we are setting every index
|
| | 131 | % it's still uniform
|
0.012 | 2 | 132 | if ~obj.NeedsUniformCheck && (~isempty(setxor(idx,1:numel(C))) || any(newType ~= newType(1)))
|
< 0.001 | 2 | 133 | obj.NeedsUniformCheck = true;
|
< 0.001 | 2 | 134 | end
|
< 0.001 | 2 | 135 | end
|
Other subfunctions in this file are not included in this listing.