Simple class counter running each step

4 ビュー (過去 30 日間)
Ludo Houben
Ludo Houben 2023 年 9 月 1 日
回答済み: Ludo Houben 2023 年 9 月 1 日
I want to create a 'simple counter' class (so I understand how it works), that increases the count value every time it is called.
classdef SimpleCount
properties
Property1 uint16 = 0
end
methods (Access = protected)
function y = stepImpl(obj,AddValue)
obj.Property1 = obj.Property1 + AddValue;
y= obj.Property1;
end
end
end
Count = SimpleCount() %declaration of instance of class
Count(5) % As 'Property1' is zero, this should result in answer = 5
Count(5) % This should result in 10
Above try gives me an error "Index exceeds the number of array elements. Index must not exceed 1."
I know how to create Methodes, but I need this code to run on a PLC (Simulink) and it must be updated every PLC scan. This counter is just for me to understand the principle, as the final implementation will be something completly different.
Thanks for any suggestions

採用された回答

Ludo Houben
Ludo Houben 2023 年 9 月 1 日
Ok found my mistake you need to call it as 'methode' step.
Count.step(5)

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeSimulink PLC Coder についてさらに検索

製品


リリース

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by