Declaring a persistant array of handle objects for XPC.

3 views (last 30 days)
Hello, I am pretty new to XPC and embedded coder so I have not got used to the not so strict declarations of data types and sizes yet. I am creating a matlab function that should be run in Simulink and eventually run on XPC target.
I want to create an array to store handles to a set of tracking filters. If I get a new target I would like to instantiate a new filter object and if the target is lost I would like to remove it from the array.
I have created a handle object
classdef WiFiTargetFilter < handle
and I´m trying to use it as follows:
function [X_est, P_est] = WiFiFilterHandler(targets, WiFiData)
persistent WiFiFilterArray;
if(isempty(WiFiFilterArray))
WiFiFilterArray(10) = WiFiTargetFilter();
end
This gives the following error:
Undefined function or variable 'WiFiFilterArray'. The first assignment to a local variable determines its class.
Then I tried to make a loop:
if(isempty(WiFiFilterArray))
WiFiFilterArray = WiFiTargetFilter();
for i = 1:10
WiFiFilterArray(i) = WiFiTargetFilter();
end
end
Of course this gives array out of bound error. How do I solve the initial declaration?? Is it possible to make the array dynamic like a list in C#?
When I remove an object I use the following code but it does not work as delete can not be used with embedded coder for some reason. What is the best approach to delete objects from the array?
if(validFilter == 0)
delete(WiFiFilterArray(f));
WiFiFilterArray(f) = [];
noTargetFilters = noTargetFilters - 1;
end
Thanks in advance! Niclas

Answers (0)

Community Treasure Hunt

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

Start Hunting!