フィルターのクリア

Info

この質問は閉じられています。 編集または回答するには再度開いてください。

Two classes being executed at the same time, sharing information

2 ビュー (過去 30 日間)
Pablo García Auñón
Pablo García Auñón 2017 年 6 月 21 日
閉鎖済み: MATLAB Answer Bot 2021 年 8 月 20 日
Hello everybody
I have two classes, A and B, being B a property of A. B is continuously making some calculations, with its own pace, while A is making others. At some point, A requests information to B. This would be a simplification of both classes:
A:
classdef AClass
properties
B
end
methods
function obj = AClass()
B = BClass();
while true
count = B.getCount;
disp(['Count now: ',num2str(count)])
pause(2)
end
end
end
end
B:
classdef BClass
properties
count = 0
end
methods
function obj = BClass()
while true
obj.count = obj.count + 1;
pause(1)
end
end
function output = getCount(obj)
output = obj.count;
end
end
end
Of course executing AClass does not work as it would be expected, since it gets stuck in the while loop, inside B. I was wondering if there is a way of making it work.
For instance in ROS (Robot Operating System), it would be pretty easy. A would be executed in a node and B in another, and each time A needs the information from B, either it is subscribed to a topic or uses a service.
Thanks a lot in advance

回答 (0 件)

この質問は閉じられています。

Community Treasure Hunt

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

Start Hunting!

Translated by