MATLAB: Do I get the error “Undefined function or variable”

I received this errors. But I don't know why. Can you help me to fix it?
Undefined function or variable 'D_fun'.
Error in run_ensembleD_func (line 6)
D_fun = D_fun + D;

Best Answer

It appears that one of the script file run_ft.m or structfun_def_v1.m have a statement like
clear all
this statement is deleting all variables from base workspace. Hence D_fun is undefined. Also, it is better to use functions to avoid such errors, since each function has its own workspace. It removes the possibility of accidentally deleting variables.
Related Question