Running Matlab Algorithim in Simulink

1 view (last 30 days)
Hello, Recently I have coded an algorithim in matlab that could take two images of clouds and see how far they have moved and then calculate how long it would take to cover the sun. This algorithim used matlab functions like bwboundareas. I want to run this now in simulink to make a real-time simulation in which clouds are read in from a video a file and then processed in this matlab algorithim to do this I tried using the typical video reader in Simulink and then it would send it to an embedded matlab function. At first I got the error that i needed to call extrinsic functions and I read that i just call them at the top with coder.extrinsic but then I got the following areas and I can't seem to figure how to resolve them. Function output 'y' cannot be of MATLAB type.
Function 'MATLAB Function' (#323.0.68), line 1, column 1: "function y = fcn(u)" Launch diagnostic report.
Errors occurred during parsing of MATLAB function 'MATLAB Function'(#323)
MATLAB Function Interface Error: Errors occurred during parsing of MATLAB function 'MATLAB Function'(#323)
MATLAB Function Interface Error: Error in port widths or dimensions. Output port 1 of 'untitled/MATLAB Function/u' is a [614x768] matrix.
Again what I want this algorithim to do is to take an image to some image processing in matlab and then output how long it will take to collide with the sun. This error occured when I was trying to do something simple like threshold the image in matlab and then output it. I know this is a long post but thank you for your time if you read it I'm definitely doing fundamentally wrong here.

Accepted Answer

Guy Rouleau
Guy Rouleau on 20 Jul 2011
To make a real-time application, you will need to generate code for the model. If you use a function that need to be declared as extrinsic, you will not be able to generate code. This set of function is listed here:
This means that you will need to implement your algorithm using a combination of: -blocks from the computer vision blockset -basic Simulink blocks -The list of function above -in a C/C++ s-function
If you are still interested in solving the question you posted, this is probably because ports dimensions are not clearly defined. In the embedded MATLAB function block editor, edit the data ports properties and set the dimensions you expect. See details here:
  2 Comments

Sign in to comment.

More Answers (1)

Alexander Bottema
Alexander Bottema on 20 Jul 2011
Hello David-Linus,
The first error you see tells you to declare functions coder.extrinsic() because the particular MATLAB function you're trying to call is not supported for code generation. You can go ahead and declare it extrinsic and let MATLAB evaluate it, but then you'll not get the C code real-time processing you're looking for.
Extrinsic functions require some special rules, as they are not analyzed. In partciular the return values are of generic MATLAB type and the code generation is unable to continue if you try to access it. Assume 'foo' is an extrinsic function and it returns a value, then you need to:
y = zeros(1,10); % Dummy init ('y' is of type 1x10 double)
y = foo(); % Checks that foo() actually returns 1x10 double
However, you'll never achieve standalone and real-time C code this way; it's for simulation only.
If extrinsic functions cannot be used (e.g. you really want standalone C code), then the only remaining option is to lookup which functions are supported for code generation (from the doc) and then write all the other functions yourself in the supported subset.
Thanks, Alexander

Community Treasure Hunt

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

Start Hunting!