How can I create an array of advanced system objects and perform the step method on individual array elements?

12 views (last 30 days)
I want to create an array of an advanced system object. The object is defined as shown in the code below:
classdef array_test2 < matlab.System
properties
% Public, tunable properties.
Value
end
methods
function obj = array_test2(F)
if nargin ~= 0 % Allow nargin == 0 syntax
m = size(F);
obj(m) = array_test2; % Preallocate object array
for i = 1:m
obj(i).Value = F(i);
end
end
end
end
end
function y = stepImpl(obj,u,v)
y = u*v;
end
Now I create an object of array_test2 as follows:
F = [1;2;3;4;5];
Arr_Test = array_test2(F); % Create 5-by-5 array of objects
This results in the following error:
Array formation and parentheses-style indexing with objects of class 'array_test2' is not allowed. Use objects of class 'array_test2' only as scalars or use a cell array.
I noticed that if I delete: < matlab.System, which is placed after classdef array_test2, the error will not appear. When I now try to perform a step on the first object of Arr_Test as follows:
y = step(Arr_Test(1),1,5);
This results in the following error:
Error using tf (line 287) The values of the "num" and "den" properties must be row vectors or cell arrays of row vectors, where each vector is nonempty and containing numeric data. Type "help tf.num" or "help tf.den" for more information.
It appears to me that I should not delete < matlab.System. Is there anyone who knows how I can create an array of avandced system objects and how I can perform the step method on each object in the array separately?

Accepted Answer

Adam
Adam on 10 Jun 2014
I came across the same problem just today trying to create an array of dsp.VariableFractionalDelay System Object by
dsp.VariableFractionalDelay.empty( NumElements, 1 )
but got this error message:
Creating an empty array of class 'dsp.VariableFractionalDelay' is not allowed. Use objects
of class 'dsp.VariableFractionalDelay' only as scalars.
My solution was to use a cell array to hold the individual System Objects. In my case, I want to process an array of data x which has NumElements columns, where each column is a separate channel, and process each column separately with its own delay:
% Create cell array to hold the System Objects
hDelays = cell( NumElements, 1 );
% Create first variable fractional delay object
hDelays{ 1 } = dsp.VariableFractionalDelay;
% Create the remaining variable fractional delay objects by cloning
for ind = 2:NumElements
hDelays{ ind } = clone( obj.hDelays{ 1 } );
end
% Execute step on each array object and each input channel (column of x ) separately
y = zeros( size( x ) );
for ind = 1:NumElements
y( :, ind ) = step( hDelays{ ind }, x( :, ind ), DelaysInSamples( ind ) );
end
  2 Comments
Raymond
Raymond on 11 Jun 2014
Edited: Raymond on 11 Jun 2014
Thank you!! I used the cellarray, edited your code a little bit. For me this works, without using the clone function:
% Create 5x1 cell array to hold 5 System Objects
Cellarray = cell(5,1);
% Create 5 arraytest_2 objects by assigning them to Cellarray
for i = 1:5
Cellarray{i} = array_test2;
end
% Execute step on each array object and each input channel separately
for i = 1:5
y(i) = step(Cellarray{i}, 4,2)
end
Adam
Adam on 20 Jun 2014
I did the cloning because I wanted to reuse the configuration I used for the first object. Glad it worked for you.

Sign in to comment.

More Answers (0)

Categories

Find more on Create System Objects in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!