assignin('caller',…) within a function in Matlab
问题 I created this very useful bit of code to assign variables dynamically from a struct : function getParam(param) % this function extracts the fields of structure param and assigns them % to variables of corresponding names in the caller workspace allFieldsParam = fieldnames(param); for iField = 1:length(allFieldsParam) assignin('caller',allFieldsParam{iField},param.(allFieldsParam{iField})); end The problem is that when I call getParam within a function, sometimes it works and sometimes it