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 Center および File ExchangeCreate System Objects についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by