フィルターのクリア

Using an empty vector as a parameter in a user-defined block

4 ビュー (過去 30 日間)
Pieter Cuijpers
Pieter Cuijpers 2016 年 10 月 4 日
コメント済み: Pieter Cuijpers 2016 年 10 月 13 日
I am new to coding my own blocks, and quickly ran into something I do not understand. When I simply add an empty vector as a property to my block as in the code below, I get an error (Invalid setting in block 'Dataflow/MATLAB Discrete-Event System' for parameter 'InputRateVector') but only after I try to run a simulation. It seems that having an empty vector as a property is okay, but having an empty vector as block parameter is not. Why is that? (For my purpose, having an empty vector really makes sense in some situations...)
PS. The code below is simply the standard "MatlabBlock" definition for discrete event systems, with one line added to create the property and two functions added to make sure there are no inputs or outputs to this block (that will change later when I understand what happened here...).
Thnx. Pieter
classdef MyBlock < matlab.DiscreteEventSystem & matlab.system.mixin.Propagates
% Public, tunable properties.
properties
InputRateVector = [ ];
end
properties (DiscreteState)
end
% Pre-computed constants.
properties (Access = private)
end
methods (Access = protected)
function num = getNumInputsImpl(obj)
num = 0;
end
function num = getNumOutputsImpl(obj)
num = 0;
end
function setupImpl(obj,u)
% Implement tasks that need to be performed only once,
% such as pre-computed constants.
end
function [entity, events] = entryImpl(obj, storage, entity, source)
% Specify event action in response to entity entry to a storage.
events = [];
end
function resetImpl(obj)
% Initialize discrete-state properties.
end
end
end

採用された回答

Dimitris Iliou
Dimitris Iliou 2016 年 10 月 12 日
If I understand correctly, running a Simulink model with an empty vector as a block parameter results in an error.
This behavior occurs not only with the DiscreteEventSystem block, but also with basic Simulink blocks like Gain. I do not think that it is possible to pass an empty vector as a block parameter.
Since in your case it makes sense to use the empty vector, I would suggest to use an alternative approach. Try setting the parameter to -1 instead of an empty vector and use that as a flag for your system.
  1 件のコメント
Pieter Cuijpers
Pieter Cuijpers 2016 年 10 月 13 日
Thanks, that seems like a 'generic' trick. And, luckily, negative values 'do not make sense from a normal operational point of view' for my block. So, the -1 suggestion is a good one.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeDiscrete-Event Simulation についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by