matlab level 2 s-functions with 2-dimensional inputs

조회 수: 2 (최근 30일)
Yves
Yves 2015년 2월 17일
답변: Yves 2015년 2월 19일
Hi all I'd appreciate your help, with the following problem:
I want to feed a n-dimensional Input into an S-Function, add a row in a chosen dimension, this modified Input works as output of my function. This works quite fine as long as the Input is a 1D-Vector, however i want to use 2D or 3D inputs. At least 2D inputs should be possible according to the documention.
The input i feed my function with is a [4x2] matrix.
The errors I get:
"Error in port widths or dimensions. Output port 1 of 'Test_simple/Constant' is a [4x2] matrix."
The output dimensions should be a 4x3 Matrix, however the s function fails to iniate the inputs, so i am unable to fix the output dimensions in: "setInPortDims". When I add a break right after the initiation of "setInPortDims" the same error appears and I am unable to check the dimension di of the input. So this isn't actually due to the false dimension of the output but rather tho a failed initiation.
"Error in port widths or dimensions. Invalid dimension has been specified for input port 1 of 'Test_simple/Level-2 MATLAB S-Function1'."
This shows that my assumption of a failed input initiation seems true. I am pretty sure that the function fails to initiate the inputs due to this error, now how can i fix this?
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.InputPort(1).Dimensions = -1;
block.OutputPort(1).Dimensions = -1;
block.SampleTimes = [0 0];
block.NumContStates = 1;
block.SetAccelRunOnTLC(false);
block.SimStateCompliance = 'DefaultSimState';
block.RegBlockMethod('SetInputPortDimensions', @SetInpPortDims);
block.RegBlockMethod('Outputs', @Outputs);
function SetInpPortDims(block, idx, di)
block.InputPort(idx).Dimensions = di;
block.InputPort(1).Data %just for checking Input
dim=size(di)
if dim(1)+dim(2)< 3 && length(dim)<3; %identify if Input is 1D
di=[di 2]; %Case for 1D
else
di(2)=di(2)+1; %Case for dimension > 1D
end
di
block.OutputPort(1).Dimensions = di;
function Outputs(block)
Grosse=size(block.InputPort(1).Data);
X=Grosse(2);
block.InputPort(1).Data
R=[block.InputPort(1).Data,zeros(Grosse(1),1)];
block.OutputPort(1).Data=R;
for k=1:4;
block.OutputPort(1).Data(k,X+1)=block.InputPort(1).Data(k,X)+10;
end
  댓글 수: 1
Yves
Yves 2015년 2월 19일
Hi
I've found the rather simple Solution. Since I haven't specified the datatype of the in- and outputs it seems to have failed the initialization.
So by specifying the datatypes with:
block.InputPort(1).DataTypeID = 0; block.OutputPort(1).DataTypeID = 0;
This Function works properly, the datatypeID 0 is double.
Hope this helps someone else with the same question as me.

댓글을 달려면 로그인하십시오.

채택된 답변

Yves
Yves 2015년 2월 19일
Hi
I've found the rather simple Solution. Since I haven't specified the datatype of the in- and outputs it seems to have failed the initialization.
So by specifying the datatypes with:
block.InputPort(1).DataTypeID = 0; block.OutputPort(1).DataTypeID = 0;
This Function works properly, the datatypeID 0 is double.
Hope this helps someone else with the same question as me.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Data Type Identification에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by