How to generate c code from MATLAB code as subs is not supported by MATLAB.

Hi! I am facing some issues in generating C code from MATLAB coder while I used subs. Please help me to fix this so that I can generate the C code.

 Réponse acceptée

Nothing in Symbolic Toolbox can be compiled or code generated for.
What you need to do is go through all the formula generation ahead of time. You can then use matlabFunction() with the 'File' option to generate a .m file to implement your algorithm numerically.
If you need to create your formulas at run time, then you will need to find a different approach than using the symbolic toolbox; symbolic toolbox is only available for interactive use.

5 commentaires

Thank you Walter Roberson for your prompt reply. I actually have to create formulas at the run time like I have to differentiate the elements in the matrices with respect to one variable say x and then have to substitute x in terms of other variables say t and s so that I can integrate. Right now I am using syms to generate the variables and process integration and differentiation. It would be of great help to me if you could suggest some alternatives to symbolic toolbox.
Just to give you an idea of what I am saying, please see the code below
syms x y s t
fun = x.^2+y;
A = [diff(fun,x) diff(fun,y)];
newx = s+t;%here I gave it as an example, in my case it is a bit complex
A1 = subs(A,x,newx);
Sol = int(int(A1,S,0,1-t),t,0,1);
Thank you in advance
Symbolic diff and symbolic int are also not possible to generate code for.
If your possible functions are multinomials (multiple variable extension of polynomials) with no negative powers, no division, and no trig, and no special functions such as factorial or hypergeometric function, then integration and differentiation are fairly easy with fairly simple data structures.
My functions contain trigonometric functions as well as divisions. Is there any other way in MATLAB with which I can work through. And I have one more doubt about integral2 function in matlab. Is it somehow possible to use integral2 function on the entire matrix at once. I am going for integral2 as int is not able to give solution to the function. And my matrix is a mix of functions(I mean each element of the matrix may depend on only one variable or it may even be a scalar), please suggest me some other way to do the integration. Thank you in advance.
You will either need to program in all appropriate calculus yourself or else find a C or C++ library in which someone has already done the work.
Division and trig functions make the task notably more difficult than multinomials.
OK I will try that. Thank you.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

Community Treasure Hunt

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

Start Hunting!

Translated by