Matlab - Class : how to declare an internal function returning a value

15 ビュー (過去 30 日間)
Yoshua CELNIKIER
Yoshua CELNIKIER 2022 年 12 月 16 日
コメント済み: Yoshua CELNIKIER 2022 年 12 月 17 日
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

採用された回答

Jon
Jon 2022 年 12 月 16 日
編集済み: Jon 2022 年 12 月 16 日
You must tell MATLAB that findScenarioNumber is a member function of the class you are currently in
scenarioNumber = obj.findScenarioNumber(splitDataFolder)
You must use obj as the first argument
function scenarioNumber = findScenarioNumber(obj,splitDataFolder)

その他の回答 (1 件)

Steven Lord
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.
  1 件のコメント
Yoshua CELNIKIER
Yoshua CELNIKIER 2022 年 12 月 17 日
This is exactly what I needed actually. Thanks !!

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeWhos についてさらに検索

タグ

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by