为什么我会收到错误消息:
???使用 ==> ensureCellType 时出错 输入参数过多。
==>usage_dynamicVariableNaming 中的错误 11 结果 = dataHolder.ensureCellType(str);
当我传入正确数量的参数时?
% USAGE:
clear all;
clc;
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);
%% 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(variableName)];
obj.variableValues = [obj.variableValues ensureCellType(variableValue)];
obj.variableTypes = [obj.variableTypes ensureCellType(variableType)];
end
function cellData = ensureCellType(value)
if (class(value) ~= 'cell')
cellData = cell2string(value);
else
cellData = value;
end
end
end
end
感谢您的大力帮助。它现在运行,但没有插入数据。
我在这个新问题上开了一个新线程: 数据没有成功插入到对象中