Matlab Level 2 S-functions and Arrays
4 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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 Commenti
Risposta accettata
Yves
il 17 Feb 2015
2 Commenti
Richard Crozier
il 17 Feb 2020
Modificato: Richard Crozier
il 17 Feb 2020
Sadly the newsreader is dead and therefore so is this link. Can you share the solution agin?
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Configure Block Features for MATLAB S-Functions in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!