How can I create an array of advanced system objects and perform the step method on individual array elements?
15 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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?
0 commentaires
Réponse acceptée
Adam
le 10 Juin 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 commentaires
Adam
le 20 Juin 2014
I did the cloning because I wanted to reuse the configuration I used for the first object. Glad it worked for you.
Plus de réponses (1)
Jan Kappen
le 25 Juin 2024
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?
0 commentaires
Voir également
Catégories
En savoir plus sur Create System Objects dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!