本文介绍了如何编写输出信号大小可变的S函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要编写一个块,该块将从选定目录发送所有图像文件.

I want to write a block, which sends all image files from selected directory.

图像的大小不同,因此输出信号的大小应该有所不同.

Images are of different sizes, so output signal size should vary.

不幸的是,我无法在每一步上找到改变信号大小的方法.

Unfortunately I was unable to find a way to change signal size at each step. There are many of undocumented features here, in examples like

block.OutputPort(1).DimensionsMode = 'Variable';

block.OutputPort(1).CurrentDimensions = [1 block.InputPort(1).Data];

,依此类推.我还无法推断出正确的方式来操作所有这些东西……

and so on. I was unable to deduce correct way to operate all this stuff yet...

更新

例如,此S函数

function Test_SF_01(block)
% Level-2 MATLAB file S-Function.

    setup(block);

function setup(block)

    % Register number of ports and parameters
    block.NumInputPorts  = 0;
    block.NumOutputPorts = 1;
    block.NumDialogPrms  = 0;

    % Setup functional port properties to dynamically inherited
    block.SetPreCompOutPortInfoToDynamic;

    % Register the properties of the output port
    block.OutputPort(1).DimensionsMode = 'Variable';
    block.OutputPort(1).SamplingMode   = 'Sample';

    % Register sample times
    %  [-1, 0] : Inherited sample time
    block.SampleTimes = [-1 0];

    % Register methods called at run-time
    block.RegBlockMethod('Outputs', @Outputs);

function Outputs(block)
    block.OutputPort(1).CurrentDimensions =  floor(rand(1,2)*10)+1;

导致错误

为什么?

推荐答案

以下S函数生成可变尺寸信号.他们的关键问题是Dimensions属性的初始集合定义了维度的MAXIMAL值,这在文档中是绝对不清楚的,而错误消息却是无关紧要的.

The following S-function generates variable dimension signal. They key problem was that initial set of Dimensions property defines MAXIMAL values of dimensions, which is absolutely not clear from docs, while error messages are mostly irrelevant.

function Test_SF_01(block)
% Level-2 MATLAB file S-Function.

    setup(block);

function setup(block)

    % Register number of ports and parameters
    block.NumInputPorts  = 0;
    block.NumOutputPorts = 1;
    block.NumDialogPrms  = 0;

    % Setup functional port properties to dynamically inherited
    block.SetPreCompOutPortInfoToDynamic;

    % Register the properties of the output port
    block.OutputPort(1).DimensionsMode = 'Variable';
    block.OutputPort(1).Dimensions = [10000 10000];

    block.OutputPort(1).SamplingMode   = 'Sample';

    % Register sample times
    %  [-1, 0] : Inherited sample time
    block.SampleTimes = [-1 0];

    % Register methods called at run-time
    block.RegBlockMethod('Outputs', @Outputs);

function Outputs(block)

     dims = floor(rand(1,2)*10)+1;
     block.OutputPort(1).CurrentDimensions = dims;

     data = rand(dims);
    block.OutputPort(1).Data = data;

这篇关于如何编写输出信号大小可变的S函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-20 23:22