Matlab Level 2 S-functions and Arrays
2 次查看(过去 30 天)
显示 更早的评论
My Question is the following:
I want to write an S-Function which takes an n-dimensional input, and gives as output the same Array with an added collumn in a chosen dimension.
When I try that I always end up with errors about a missmatch of dimensions:
"Error in 'SetOutputPortDimensions' method of 'Test_simple/Level-2 MATLAB S-Function1'. The dimension of output port 0 should have been set to [4x1], but was instead set to [4x2]."
&
"Error in port widths or dimensions. Output port 1 of 'Test_simple/Constant' is a [4x1x2] matrix."
How can I fix this missmatch of dimensions?
My code: -----------------------------------------------------------------------------------------------------------------------------------------------------------------
function VPSFUNC4S(block)
setup(block);
function setup(block)
block.NumInputPorts = 1;
block.NumOutputPorts = 1;
block.AllowSignalsWithMoreThan2D = 1;
block.SetPreCompInpPortInfoToDynamic;
block.SetPreCompOutPortInfoToDynamic;
block.InputPort(1).DirectFeedthrough = true;
block.OutputPort(1).DimensionsMode = 'Variable';
block.NumContStates = 1;
block.SampleTimes = [0 0];
block.SetAccelRunOnTLC(false);
block.SimStateCompliance = 'DefaultSimState';
block.RegBlockMethod('SetOutputPortDimensions', @SetOutPortDims);
block.RegBlockMethod('Outputs', @Outputs);
function SetOutPortDims(block, idx, di)
di=block.InputPort(1).Dimensions;
di(2)=di(2)+1;
block.OutputPort(idx).Dimensions = di;
function Outputs(block)
Grosse=size(block.InputPort(1).Data);
X=Grosse(2);
block.OutputPort(1).Data=block.InputPort(1).Data;
block.OutputPort(1).Data=[block.OutputPort(1).Data,zeros(1,Grosse(1))];
for k=1:4;
block.OutputPort(1).Data(k,X+1,1)=block.InputPort(1).Data(k,X,:)+10;
end
0 个评论
采纳的回答
Yves
2015-2-17
2 个评论
Richard Crozier
2020-2-17
编辑:Richard Crozier
2020-2-17
Sadly the newsreader is dead and therefore so is this link. Can you share the solution agin?
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!