MATLAB Answers

How to get a return value from a function_handle, when the function_handle is an input to a system object

조회 수: 3(최근 30일)
I am using the Sensor Fusion toolbox. When I create the trackerGNN system object, I set the property 'FilterInitializationFcn' which specifies the filter initialization function. I am using the IMM filter (@initekfimm), so I would like to plot the probability of each model over time, which is the ModelProbabilities property of the IMM filter.
I want @initekfimm to output ModelProbabilities. ModelProbabilities is a property of trackingIMM, which is called from initekfimm.
My plan was to use get(IMM, ‘ModelProbabilities’) and then have initekfimm output ModelProbabilities.
The issue is that the function initekfimm is called from trackerGNN , and trackerGNN can’t output stuff that isn’t listed as one of its properties.
Here is my code:
tracker = trackerGNN( 'FilterInitializationFcn',@initekfimm,...
I want initekfimm to output ModelProbabilities whenever the filter is called. How do I access the outputs of initekfimm?

  댓글 수: 4

표시 이전 댓글 수: 1
Mia Levy
Mia Levy 12 Aug 2019
Hi,
Thank you for your answer. What do you mean by "wrap" initekfimm, do you mean just create another function that calls initekfimm, and use that as an input to trackerGNN instead of initekfimm?
Also, how would my wrapper function be able to put the desired outputs into some variable accessible from the rest of the code?
dpb
dpb 12 Aug 2019
  1. Yes
  2. Several ways. global is the crudest and only to be relied upon for the simplest of cases or as a temporary hack to test an idea. assignin is another as is scoping functions as internal such that variables share scope.
The ideas are explained in the scope of optimization or other solvers that pass function handles but same ways to share data work for other purposes, too. Paramterize Function

Sign in to comment.

채택된 답변

Elad Kivelevitch
Elad Kivelevitch 4 Nov 2019
Mia,
You can access any property of any tracking filter used in the trackerGNN (and any other tracker) by calling the getTrackFilterProperties method of the tracker.
help trackerGNN/getTrackFilterProperties
I don't know how many objects you are tracking, but let's assume it is only one for now.
You can use the following code:
gnn = trackerGNN('MaxNumTracks',1,'FilterInitializationFcn',@initekfimm);
modelProbs = zeros(3,10); % 10 time steps
for t = 1:10
detections = {objectDetection(t,zeros(3,1))};
[~,~,track] = gnn(detections,t); % Get all tracks
mps = getTrackFilterProperties(gnn,track.TrackID,'ModelProbabilities');
modelProbs(:,t) = mps{1};
end
plot(1:10,modelProbs)
Elad

  댓글 수: 0

Sign in to comment.

추가 답변(0개)


Translated by