Problem saving/loading structure with function handles
Afficher commentaires plus anciens
Hi all, I have made a bit of code that stores information about species and stores a number of different fields that contain strings, symbolic functions, and function handles in a structure. The function handles are correctly stored and hold the path information, confirmed by using functions(). However, when I try to save the structure to a .MAT file and load it again, all of the function handle path information is gone. How should I save this in order to retain the information. Also, I have not done any changes to the actual function m-files or their folder.
-Joe
'Name' 'C'
'Tints' 3
'MM' 12.0107
'Phase' 'Gas'
'TRange' [200,1000,6000,20000]
'Cp_R' <1x1sym>
'H_RT' <1x1sym>
'S_R' <1x1sym>
'G_RT' <1x1sym>
'Density'[]
'Diameter'[]
'RedTemp'[]
'G' @C_gas
'H' @C_gas
'S' @C_gas
'Cp' @C_gas
>> functions(database(1).G)
ans =
function: 'C_gas'
type: 'simple'
file: 'C:\Users\Joe\Desktop\MATLAB_today\GasFlowMatrix\Database Files\Standard\GibbsFreeEnergy\C_gas.m'
>> save('test','database') >> functions(database(1).G)
ans =
function: 'C_gas'
type: 'simple'
file: 'C:\Users\Joe\Desktop\MATLAB_today\GasFlowMatrix\Database Files\Standard\GibbsFreeEnergy\C_gas.m'
>> load test.mat
>> functions(database(1).G)
ans =
function: 'C_gas'
type: 'simple'
file: ''
1 commentaire
Paulo Silva
le 24 Jan 2011
I never used the function functions before but I notice a strange behavior, some functions have something in the file line and others don't
functions(@spy)
ans =
function: 'spy'
type: 'simple'
file: 'C:\Program Files (x86)\MATLAB\R2008b\toolbox\matlab\sparfun\spy.m'
functions(@sin)
ans =
function: 'sin'
type: 'simple'
file: ''
functions(@pi)
ans =
function: 'pi'
type: 'simple'
file: 'MATLAB built-in function'
Réponse acceptée
Plus de réponses (1)
Bruno Luong
le 24 Jan 2011
1 vote
In an old related thread below, there is a way to deal with loading/saving function handle: http://www.mathworks.com/matlabcentral/newsreader/view_thread/235926
Bruno
Catégories
En savoir plus sur File Operations dans Centre d'aide et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!