简体   繁体   中英

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM