- Split the computation into smaller pieces: If the integer values used in your MATLAB function are part of a large computation, you can split the computation into smaller pieces to avoid integer overflow errors.
- Use modular arithmetic if possible: If the integer values used in your function are only used in arithmetic operations such as addition, subtraction, multiplication, or division, you can use modular arithmetic to avoid integer overflow errors.
Simplify handle function values for export to c++
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Hello,
I have some handle functions that I need to export to c++, but my issue is that this functions have inside very large integer values so i'm struggling then in c++ as I cant store those large int numbers.
So to solve that, I'm trying to somehow simplify this functions before exporting. I did a trial but the resulting values are the same than the input ones so, its not simplifying. I dont know if my approach is good, but I dont have more Ideas on how to overcome this problem.
I attached my functions "fregs_TX90.mat" and a little script with my trial on one of those functions:
clear all;
close all;
clc;
%%
load('fregs_TX90.mat', "q","dq","ddq","freg","fregM","fregG","fregCentr","fregCentrCor","fregCentrCorG","fregFric","fregCentr","fregCor");
%%
clc;
%fregMat=freg(ddq(1),ddq(2),ddq(3),ddq(4),ddq(5),ddq(6),dq(1),dq(2),dq(3),dq(4),dq(5),dq(6), q(2),q(3),q(4),q(5),q(6));
fregMMat= fregM(q(2),q(3),q(4),q(5),q(6));
% fregGMat= fregG(q(2),q(3),q(4),q(5),q(6));
%fregCentrCorMat= fregCentrCor(dq(1),dq(2),dq(3),dq(4),dq(5),dq(6), q(2),q(3),q(4),q(5),q(6));
%fregCentrCorGMat= fregCentrCorG(dq(1),dq(2),dq(3),dq(4),dq(5),dq(6), q(2),q(3),q(4),q(5),q(6));
% fregFricMat= fregFric(dq(1),dq(2),dq(3),dq(4),dq(5),dq(6));
% fregCorMat= fregCor(q(2),q(3),q(4),q(5),q(6));
%fregCentrMat= fregCentr(q(2),q(3),q(4),q(5),q(6));
fregMMatsimp=simplify(fregMMat)
0 comentarios
Respuestas (1)
Amit Dhakite
el 12 de Abr. de 2023
Editada: Amit Dhakite
el 12 de Abr. de 2023
Hi Mikel,
As per my understanding, you want to convert your MATLAB code to C++ code, but the large integer values are not supported in C++.
It's not clear what exactly the fregM() function is doing, but I can suggest some general measures you may consider to avoid these type of situations while implementing functions in MATLAB:
The simplify() function itself does not directly deal with overflows of integer values. It only simplifies expressions symbolically, without evaluating them numerically. However, it is possible that some expressions may result in an overflow even after using simplify() function.
With regards,
Amit
0 comentarios
Ver también
Categorías
Más información sobre Call C++ from MATLAB en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!