Drexel dragonThe Math ForumDonate to the Math Forum



Search All of the Math Forum:

Views expressed in these public forums are not endorsed by Drexel University or The Math Forum.


Math Forum » Discussions » Software » comp.soft-sys.matlab

Topic: Level 2 Matlab S-Function
Replies: 2   Last Post: Mar 18, 2013 6:23 AM

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]
Kwok

Posts: 8
Registered: 5/31/12
Level 2 Matlab S-Function
Posted: Jun 7, 2012 9:27 AM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

I have a very simple simulink model which uses S-function to output a 2x2 matrix to display block. The matrix is initialized in matlab workspace, and it is input to the s-function through dialog parameter. The input to this s-function block is just the constant block with value of 1. It gives me an error message "Error in 'SetOutputPortDimensions' method of ...... The dimensions of output port 0 should have been set to [1], but was instead set to [2x2]"

I tried many different ways, but I cant get this to work. Thanks.

My code is below:
function test4(block)
setup(block);

function setup(block)
block.NumInputPorts = 1;
block.NumOutputPorts = 1;
block.SetPreCompInpPortInfoToDynamic;
block.SetPreCompOutPortInfoToDynamic;
block.InputPort(1).DatatypeID = 0; % double
block.InputPort(1).Complexity = 'Real';
block.OutputPort(1).DatatypeID = 0; % double
block.OutputPort(1).Complexity = 'Real';
block.NumDialogPrms = 1;
block.SampleTimes = [-1 0];
block.SimStateCompliance = 'DefaultSimState';
block.RegBlockMethod('SetInputPortSamplingMode', @SetInpPortFrameData);
block.RegBlockMethod('SetInputPortDimensions', @SetInpPortDims);
block.RegBlockMethod('SetOutputPortDimensions', @SetOutPortDims);
block.RegBlockMethod('Outputs', @Outputs);

function SetInpPortFrameData(block, idx, fd)
block.InputPort(1).SamplingMode = fd;
block.OutputPort(1).SamplingMode = fd;

function SetInpPortDims(block, idx, fd)
block.InputPort(1).Dimensions = 1;

function SetOutPortDims(block, idx, fd)
block.OutputPort(1).Dimensions = [2 2];

function Outputs(block)
a=block.DialogPrm(1).Data;
block.OutputPort(1).Data = a;



Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© Drexel University 1994-2014. All Rights Reserved.
The Math Forum is a research and educational enterprise of the Drexel University School of Education.