Is it possible to call external matlab functions from a tlc file?

I have a Level-2 Matlab S-function that calls a great number of other matlab functions in order to perform a routine. It is a lot of code and I wonder if is possible to do a wrapper for a level-2 matlab function or if is possible to call those functions (the ones originally called from my Level 2 S function) from the TCL file. I know this is possible with C Sfunctions, but I have not find anything about doing it with matlab.|

Respuestas (1)

Titus Edelhofer
Titus Edelhofer el 6 de Sept. de 2012
Hi,
no, this is not possible. It would not make too much sense anyway: you need the .tlc file for code generation, but you would need to convert the MATLAB code called by your S-Function into C code in some way ...? Depending on your release you could use an Embedded MATLAB Function block or MATLAB Coder to fulfill the task ...
Titus

7 comentarios

One point missing: in tlc you can evaluate MATLAB functions to support the process of code generation, see for "FEVAL" in the Target Language Compiler, section "TLC Build-In Functions". But in the generated code you can't use a MATLAB expression, because the output of tlc is C, not MATLAB.
Xenoepist
Xenoepist el 6 de Sept. de 2012
Editada: Xenoepist el 6 de Sept. de 2012
First of all, thanks for your prompt answer.
Not directly, but is it possible to compile my "*.m" functions using matlab's "mcc" command and then call the compiled "*.exe" functions from the TCL file? Or is there another way I can compile the S-function without rewriting all my matlab external functions.
Xenoepist
Xenoepist el 7 de Sept. de 2012
Editada: Xenoepist el 7 de Sept. de 2012
Ok, I just discovered Matlab Coder. It transforms matlab code to C. I made a test function that multiplies 2 intputs [ gain(num1, num2) ] and returns the result. IE gain(2,3) returns 2*3 = 6. After compiling the function and trying gain_mex(2,3) it returns 6 as expected :). Now, when I try:
%implements "wrapping" "C"
%function BlockTypeSetup(block, system) void %openfile buffer extern real_T gain(real_T mul, real_T k); %closefile buffer
%<LibCacheFunctionPrototype(buffer)> %endfunction %% BlockTypeSetup
%function Outputs(block, system) Output /* Multiply input by two */
%assign rollVars = ["U", "Y"]
%roll idx = RollRegions, lcv = RollThreshold, block, "Roller", rollVars
%assign k = 4
%assign mul = 3
%<LibBlockOutputSignal(0, "", lcv, idx)> = \
%<LibBlockInputSignal(0, "", lcv, idx)> * gain(%<mul>,%<k>);
%endroll
%endfunction
I tried to compile the model and it gives me an error and matlab does not give detail. It just says: Error(s) encountered while building model "untitled"
of course I am half assleep and this is not going to work because the function is inside "codegen/lib/gain" folder. How can I call the C function that is placed in another folder? I tried
...extern real_T codegen/lib/gain/gain(real_T mul, real_T k); ...codegen/lib/gain/gain(%<mul>,%<k>) (just adding the path) but it didn't work :/
I'm coming back to the last part of my answer: have you thought about using the MATLAB Function Block? The code in there get's compiled to C-code without the need to write a .tlc file ...
Well, the problem is that the function I'm going to be using is already made and it is very long and complicated. It is divided into smaller ".m" matlab functions. What I want to do is compile each ".m" function into a ".c" function and call each function from my "S-function."
The other problem that I have is that my professor won't even show me the ".m" functions until I've learned to call ".c" functions from the TLC.
The function that I used in the example is not the one I need to compile. It is just a simple one I made to understand more complicated ones.
Hi
Did you managed to solve the issue??
If yes then please guide as I am having the same trouble.
Regards

Iniciar sesión para comentar.

Categorías

Productos

Preguntada:

el 5 de Sept. de 2012

Comentada:

el 9 de Oct. de 2014

Community Treasure Hunt

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

Start Hunting!

Translated by