Matlab - Class : how to declare an internal function returning a value
17 次查看(过去 30 天)
显示 更早的评论
Hi all, I am trying to declare an internal function (findScenarioNumber) in a class. This function is supposed to output a number. But I have an error in the line "scenarioNumber = findScenarioNumber(splitDataFolder);" where I'm calling the function: Undefined function 'findScenarioNumber' for input arguments of type 'cell'. Searching but cannot find the good syntax to do that. Anyone can help ?
Here is my code :
classdef SignalStructureProperty < handle
properties
signals
end
methods
function obj = createSignalTopLevelStructure(obj,dataFolder)
splitDataFolder = split(dataFolder,'\');
scenarioNumber = findScenarioNumber(splitDataFolder);
obj.signals.metaData.scenarioNumber = scenarioNumber;
end
function scenarioNumber = findScenarioNumber(splitDataFolder)
scenarioNumber = NaN;
if(~isempty(splitDataFolder))
for i=1:length(splitDataFolder)
if(contains(splitDataFolder{i},'SCN'))
scenarioNumber = str2double(extractAfter(splitDataFolder{i},"SCN"));
end
end
end
end
end
end
0 个评论
采纳的回答
更多回答(1 个)
Steven Lord
2022-12-16
I would make findScenarioNumber a class-related function rather than a method of the class. See this documentation page for an example of this technique.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Subclass Definition 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!