release structure
Mostrar comentarios más antiguos
Dear all:
I try to set a separate file for parameters in a model, and I want to retain their name so later on I can do sensitivity analysis using string comparison to identify the parameter name. So I define my parameters into structures, such as:
param.eps = 6;
param.beta = 0.99;
param.theta = 0.7532;
param.gamma = 0.5;
I want to release the structures into into variables as the following:
eps = 6;
beta = 0.99;
theta = 0.7532;
gamma = 0.5;
Is there an automatic way for doing this? I suspect I can setup the structure contains the name and value separately, and I probably can run a loop to equate the name with the value. But I think there must be a quicker and better way of doing this...
Any comments will be appreciated.
Cheers
Ben
Respuesta aceptada
Más respuestas (1)
Oleg Komarov
el 1 de Ag. de 2011
Why would you like to do such a thing?
% A method that avoids eval:
fnames = fieldnames(param);
save('param.mat','-struct','param')
load('param.mat')
delete('param.mat') % Or save it in the temp folder
2 comentarios
Ben Wang
el 1 de Ag. de 2011
Oleg Komarov
el 1 de Ag. de 2011
Why can't you keep the structure. It's there for this reason and allows you to dynamically index the fields.
Categorías
Más información sobre Structures 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!