數據未成功插入。數據未成功插入對象
輸出:
dataHolder.variableNames = []
當它應該是:
dataHolder.variableNames = [{'area_12345[<>]6789'}, {'apollo123'}, {'guruX'}, {'ok'}];
%用法:
elementNames = {'area_12345[<>]6789', 'apollo123', 'guruX', 'ok'};
elementTypes = {'string', 'specialChar', 'int', 'float'};
elementValues = {'charlie', 'vvv', '09', '123.321'};
dataHolder = dynamicVariableNaming;
str = 'test';
result = dataHolder.ensureCellType(str);
for i = 1:3
dataHolder.addVariables(elementNames(i), elementTypes(i), elementValues(i));
end
dataHolder.variableNames
%%% CLASS
classdef dynamicVariableNaming
%HELLO Summary of this class goes here
% -
properties
variableNames = [];
variableValues = [];
variableTypes = [];
end
methods (Access = public) % (Access = private)
function obj = dynamicVariableNaming (variableName, variableValue, variableType)
% class constructor
if(nargin > 0)
obj.variableNames = variableName;
obj.variableValues = variableValue;
obj.variableTypes = variableType;
end
end
% end
%
% methods (Static = true)
function addVariables (obj, variableName, variableValue, variableType)
obj.variableNames = [obj.variableNames ensureCellType(obj, variableName)];
obj.variableValues = [obj.variableValues ensureCellType(obj, variableValue)];
obj.variableTypes = [obj.variableTypes ensureCellType(obj, variableType)];
end
function cellData = ensureCellType(obj, value)
if (~strcmp(class(value), 'cell'))
cellData = {value};
% cell2string(value);
else
cellData = value;
end
end
end
end
我同意@HighPerformanceMark。 Hovewer,你的bug很簡單...看我的回答 – KlausCPH