所以,我是applying for a job,需要弄清楚how nested functions work。更具體地說,我想知道gnovice發佈的以下示例是如何工作的。嵌套函數在MATLAB中如何工作?
的問題是:
考慮下面的函數,將輸出在命令窗口中輸入下面的代碼時會是什麼?
function fcnHandle = counter
value = 0;
function currentValue = increment
value = value+1;
currentValue = value;
end
fcnHandle = @increment;
end
f1 = counter();
f2 = counter();
output = [f1() f1() f2() f1() f2()]; %# WHAT IS IT?!
我不是找工作,我能回答弄清楚這個問題。我還發現the answer從Mohsen到this question直觀(找到矩陣的大小而不調用內置函數)。但是,我忍不住聽到了阿爾伯特愛因斯坦的聲音。
我覺得documentation有點亂亂的,所以我會非常高興,如果有人能夠解釋它是如何工作的。
+1在聽到你的頭! :-) – 2014-10-07 15:09:32