Variables from a .mat file, loaded with "coder.load" in a mex-file, remain equal when I change the value of the content of the mat.file

4 views (last 30 days)
Hi everyone!
This is my first time asking a question, so I hope I can give you a good description of my problem so someone can help me.
I have created a mex file from a .m.
The mexfile read a couple of variables from a .mat file using the function coder.load('name.mat') :
DatosInput = coder.load('name');
m_est = DatosInput.mest;
R_est = DatosInput.rs;
L_est_disper = DatosInput.lls;
L_est_mag_1 = DatosInput.lm;
m_rot = DatosInput.m_rot;
R_rot = DatosInput.rpr;
L_rot_disper = DatosInput.mest;
Par_resistenteValor =DatosInput.Tres;
J_inercia = DatosInput.J;
p = DatosInput.p;
fmostens = DatosInput.fmostens;
tfinal = DatosInput.tfinal;
U_aux = DatosInput.U_linea;
The thing is that the value of the variables stored in "name.mat" are not always the same (in size and value), because externaly everytime a different .mat file is generated, however, the amount of variables are always the same.
The problem is that, once I compile the mex-file using MATLAB Coder and change the original values of the name.mat, the mexfile continue operating with the original values which with the mex-file was created during the compiling.
Thank you very much.
  8 Comments
dpb
dpb on 23 May 2019
After re-reading the documentation link, I see now that is indeed the documented bethavior.
It's not totally clear that's what they mean I think on first reading because one just doesn't really expect that kind of behavior for a function with the name and the way the regular load function works.
To do so at run time will take a different route--not sure what can be used in the environment you're working in, though, for specifics.
Jorge Bonet Jara
Jorge Bonet Jara on 24 May 2019
Edited: Jorge Bonet Jara on 25 May 2019
I agree with you that it is not totally clear. But, anyway, it seems that this is the current behaviour of the function load when you compile the function as a mex file. Whatever, I open a query to the matlab support service, maybe there is another alternative.
pd: I tested with coder.load and load, and both of them have the same behaviour.
Thank you very much for your time.
Edit:
I contacted matlab support and they gave a solution that works:
%#codegen
coder.varsize('Parametros2.Conexion')
coder.varsize('Parametros2.U_linea')
coder.varsize('Parametros2.tout')
Parametros2=load('C:\Users\Joan\Desktop\Simulador\FASES INDEPENDIENTES\Buenos seguros\SeñalesYDatosSim\Parametros2.mat');
m_est = Parametros2.mest;
R_est = Parametros2.rs;
L_est_disper = Parametros2.lls;
L_est_mag_1 = Parametros2.lm;
m_rot = Parametros2.m_rot;
R_rot = Parametros2.rpr;
L_rot_disper = Parametros2.lplr;
Par_resistenteValor =Parametros2.Tres;
J_inercia = Parametros2.J;
p = Parametros2.p;
fmostens = Parametros2.fmostens;
tfinal = Parametros2.tfinal;
U_aux = Parametros2.U_linea;
Conexion = Parametros2.Conexion;

Sign in to comment.

Answers (0)

Products

Community Treasure Hunt

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

Start Hunting!