Anatoly
Anatoly

Reputation: 87

Matlab function as Simulink block

I tryed to write an Matlab function in Simulink. My first func like this:

function y = fcn(u, v)
coder.extrinsic('detectSURFFeatures');
boxPoints = detectSURFFeatures(u);
%scenePoints = detectSURFFeatures(v);
vBoxPoints = boxPoints.selectStrongest(100);
y = 0;
y = vBoxPoints;

But I see errors: 1. Attempt to extract field 'selectStrongest' from 'mxArray'. 2.Undefined function or variable 'vBoxPoints'. The first assignment to a local variable determines its class. 3. Error in port widths or dimensions. Output port 1 of 'detecting_cross/MATLAB Function/v' is a [400x239] matrix. Pls, help.

Upvotes: 1

Views: 4148

Answers (1)

Navan
Navan

Reputation: 4477

The data returned from extrinsic functions are mxArray types. If you want to get the values from these mxArrays you need to pre-declare them so that the result of extrinsic function can be auto-converted to that type. You can use something like

boxPoints = struct('selectStrongest',zeros(100,1));

before calling detectSUTFFeatures. If the mxArray does not match the one from the function, you will get a run-time error. Your errors 2 and 3 are because of the first problem.

Upvotes: 4

Related Questions