Warning: Struct field assignment overwrites a value with class "function_handle".
Show older comments
Hello,
I'm building a GUI where I would like to let the user choose two functions, the first one is shotrad.m and the second one is IFOModel.m. The function shotrad.m that takes as input frequency f and IFOModel. IFOModel is function that has some constants in it. Therefore, when evaluating the function, it should look like: shotrad(f,IFOModel). So far the code looks like this
%add shotrad file
[shotradf,shotradpath] = uigetfile('*.m','Select the Shotrad code file'); %let the user choose the shotrad file
shotrad_file=shotradf(1:length(shotradf)-2); %eliminate .m from string
addpath(shotradpath); %add path of file
% add IFOModel file
[ifof,ifopath] = uigetfile('*.m','Select the IFOModel code file'); %let the user choose the IFOModel file
ifo_file=ifof(1:length(ifof)-2); %eliminate .m from string
addpath(ifopath); %add path of file
%now use str2func convert strings to functions
shotrad = str2func(shotrad_file);
IFOModel = str2func(ifo_file);
%evaluate the function, here's where the problem is
n=shotrad(f,IFOModel);
end
In the last step, where I try to evaluate n, I get the warning: Warning: Struct field assignment overwrites a value with class "function_handle", and after that, it will drop an error: ??? Reference to non-existent field 'Constants'.
the function IFOModel has the following structure
function ifo=IFOModel(varargin)
ifo.Constant.c=3e8
%and it has other constants included as structure
end
Why am I getting this problem and how can I fix it. Thank you!
2 Comments
Guillaume
on 13 Jul 2015
The problem is within shotrad itself. So, show that code.
Doesn't the error shows the line where it occurs?
Walter Roberson
on 13 Jul 2015
You mention that the error has to do with the field "Constants" but your IFOModel has a field "Constant" so perhaps you have a problem with inconsistent field names.
Answers (0)
Categories
Find more on Structures in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!