Implementing your own function in a simulink model

I have written a simple color filter function in MATLAB 2010a. I am trying to create a Simulink model where I can pass live video through this function so that I can see only the color blue, however I never seem to find the right block for user defined functions. I have tried the Embedded MATLAB function, but it never seems to work and I don't think it is for what I am trying to do. I have tried the function block, but that only takes a one dimensional input, video has three. The other option is s-functions, but I don't know if that is too complicated for what I am trying to do. I would appreciate it if someone could point me in the right direction.
Thanks,
Roshan

 Accepted Answer

Look at examples like the penddemo, inside the animation subsystem (look under mask) there's one s-function block that interacts with the simulation, the code for it is implemented on just one m file (s-function parameters), maybe you can do the same.

More Answers (1)

I wrote the following post especially to give tips on finding the best implementation for your for problems like yours:
Based on the description you give, I would go for a level 2 MATLAB s-function. It is not as complicated as it seems and give you all the power of MATLAB. If you plan to generate code for deployment on a real-time system, then I recommend Embedded MATLAB.

2 Comments

Thank you Paulo Silva and Guy Rouleau. I accept both of these answers, I'm not sure why I wasn't able to select both of your answers, but both were very helpful. I was wondering if you could again answer the following question for me. I have added a function to my s function block and I believe that I must register the function using the following line of code:
block.RegBlockMethod('WriteRTW', @WriteRTW);
What is @WriteRTW? I believe that 'WriteRTW' is another function in the block and does @WriteRTW mean that it will store the output from 'WriteRTW' into the variable WriteRTW?
Furthermore, what does block.NumDialogPrms mean? The default setting for this seems to be 3.
Thanks,
Roshan
"@" is to define a function handle, do a quick doc search for "function handle" to learn more on that topic. Note that you don't really need it here. Type "sfundemos" in MATLAB to open all the s-function demos. Then look in the MATLAB files ection and the Level 2. You will find many examples and the template. I recommend always starting form a demo or the template to make you blocks.
To answer "what does block.NumDialogPrms mean?", please use the doc or try your intuition... Num as in "Number", dialog as in "dialog" and "Prms" s in parameters... assemble that and you have a parameter defining the number of dialog parameters of your block ;-)
http://www.mathworks.com/help/toolbox/simulink/slref/simulink.runtimeblock.html
HTH,
Guy

Sign in to comment.

Categories

Find more on Block and Blockset Authoring in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!