Load constants from file
21 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Hi,
I'm looking for a way to load constants defined in an external file to the workspace, keeping their original names.
I generate a row of constants, using an external application, that looks like this:
A=1
B=2
C=3
Now, I'd like to load this data (which is stored in a file) into the Matlab workspace, preserving the constant names, so that, after the import, the A, B and C constants with the corresponding values are visible in the workspace and usable in my model.
I have full control on the imported file's format, too.
Any idea on how to achieve this, is greatly appreciated! Thank you!
0 comentarios
Respuesta aceptada
Gerd
el 1 de Jul. de 2011
Hi Cristian,
you can use the eval('') command to do what you described. First you have to open the file, read line by line and
eval('A=1');
Then you have the variable in your base workspace.
Gerd
Más respuestas (2)
Daniel Shub
el 1 de Jul. de 2011
Another solution is to create a file, lets call it loadconstants.m. In that file just put
A=1;
B=2;
C=3;
Then when you want to load the constants simply type
loadconstants
ravindra
el 2 de Jul. de 2011
Hello, I am also having same problem means I have a file name A which is having 12X36 matrix. I want to use it in my model which I am writting in .m file. So how to use this file in my program. Please help me Thank you
Ver también
Categorías
Más información sobre Variables 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!