Is there an alternative to Eval() ? - Large equation in a text file needs to be evaluated in Simulink
Mostrar comentarios más antiguos
Hello,
I have a large text file (>150MB)as a result of a symbolic calculation that includes elements of a matrix in the form of:
A(i)= ...; (where i=1,2,...,15)
I created a Simulink block that runs a C Mex S-function to evaluate the matrix from the text file. I need the Simulink model to design a controller for a mechanical system.
The method I am using right know is solely based on "eval()" that is included in a Matlab function which is called by "mexCallMATLAB()" from the S-function. This is very inefficient timewise.
Another method I tried was converting the Matlab code into C code using built-in "ccode()" function. This would have been ideal to use in a C Mex S-function. In this case, however, maple generated too many intermediate variables which I thought was hard to keep track of and eliminated this option.
I would like to learn if there is a better way of handling this kind of a scenario in terms of reduced time for that block to produce results. Thank you for your comments/suggestions in advance.
Regards,
Ernur Karadogan
Respuestas (2)
Walter Roberson
el 15 de Feb. de 2011
In Maple, did you try
codegen[C](Expression,optimized)
Though the optimized option will introduce many more intermediate variables than if you do not optimize.
Is your Maple new enough to use
CodeGeneration[Matlab](Expression)
The expression can be followed by optimize=true or optimize=tryhard though either one might make the code harder to follow.
5 comentarios
Ernur
el 15 de Feb. de 2011
Walter Roberson
el 15 de Feb. de 2011
You mention "maple" in one place -- was that a typo ?
Ernur
el 15 de Feb. de 2011
Walter Roberson
el 15 de Feb. de 2011
Which version are you using? Since about 2008, MuPad would be used instead of Maple. If you are using a 2007 or earlier version, then I _suspect_ you could get the access to the Maple code generation functions, but I am not certain (I don't have the toolkit to try with.)
If you are using a newer version that uses MuPad, have you considered using matlabFunction() ?
Ernur
el 5 de Mzo. de 2011
Ernur
el 15 de Feb. de 2011
1 comentario
Walter Roberson
el 5 de Mzo. de 2011
Or you could just rename the .txt files ;-)
Categorías
Más información sobre Evaluation en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!