Generating C Code from Matlab Code containing ODE15s Solver
Mostra commenti meno recenti
Hi Everyone,
I'm trying to generate a c code from my matlab code using matlab coder. My matlab function contains a set of variable as an output from a ode15s solver. I have tried everything to define the output vector and matrice before calling the ode function but I receive the error "undefined variable or function" both for the time vectore "T" and the matrice of variables:
T=double(zeros((tdis*tend-tstart),1));
Y=double(zeros((tdis*tend-tstart),(z_n+1)*(n_seg*tet_n+1)+(n_seg*tet_n+1)+4));
[T,Y]=ode15s(@(ttt,y) ff8(ttt,y,Inputs),Tspan,IC,options);
Can anybode help me solving this issue?
Thanks
Risposte (1)
Harald
il 29 Giu 2023
0 voti
Hi Hossein,
it could be that you have not properly defined the input arguments of the function. My recommendation is to use the MATLAB Coder App (accessible through the Apps tab or by running coder from the Command Window). This will guide you through the workflow, particularly the proper definition of input arguments of the function.
If you continue to experience problems, please make the full function available that you are trying to generate code from, and the steps you are using to generate the code.
Best wishes,
Harald
6 Commenti
Hossein Sadri
il 29 Giu 2023
Harald
il 29 Giu 2023
Hi Hossein,
could you share an example function that uses ode15s and exhibits the problems when you try to generate code, please? Also, what MATLAB version are you using?
Best wishes,
Harald
Hossein Sadri
il 29 Giu 2023
Harald
il 29 Giu 2023
I tried to generate code using that example script, and it worked just fine for me. I know, not very helpful for you, so let's see...
- At what point in the process do you get the error about undefined variables?
- What MATLAB release are you using?
- What C compiler are you using?
I don't really think it should make a difference (and it didn't for me) but one thing I would try is to use different variable names for the outputs and function handles, e.g.
[T,Y] = ode15s(@(t,y) -10*t, tspan, y0);
plot(T,Y,'-o')
Hossein Sadri
il 29 Giu 2023
Harald
il 29 Giu 2023
I also tried in R2022b with compiler Microsoft Visual C++ 2017, and it worked for me.
There is only one more aspect that I can think of: check if you are using a supported compiler for R2022b. If the compiler you currently use is not listed, I recommend switching to a supported compiler.
You can use mex -setup to identify the compiler currently used.
If this does not help, please contact the Technical Support team. Referring to this page will help the colleagues understand what you have already tried.
Best wishes,
Harald
Categorie
Scopri di più su Ordinary Differential Equations in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!