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

조회 수: 14 (최근 30일)
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?

채택된 답변

Adam
Adam 2014년 6월 10일
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
Raymond
Raymond 2014년 6월 11일
편집: Raymond 2014년 6월 11일
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 2014년 6월 20일
I did the cloning because I wanted to reuse the configuration I used for the first object. Glad it worked for you.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Jan Kappen
Jan Kappen 2024년 6월 25일
Need to come back to this question. Apparently, matlab.System and matlab.mixin.Heterogneous are not compatible..
classdef RandomDataGeneratorBase < matlab.System & matlab.mixin.CustomDisplay & matlab.mixin.Heterogeneous
methods
function obj = RandomDataGeneratorBase()
end
end
end
Results in Method 'cat' in class 'matlab.mixin.Heterogeneous' conflicts with the sealed method in superclass 'matlab.mixin.internal.Scalar'. Overriding a sealed method is not supported.
Any ideas how to fix that?

카테고리

Help CenterFile Exchange에서 Create System Objects에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by