1.问题产生
在处理Coursera course - Algorithms for Battery Management System - Part 3 - Battery State of Charge Estimation - Week 7 - Capstone 2 - Tuning SPKF时,内嵌函数在jupyter notebook的octave环境下运行无报错,在octave GUI运行时报错nested functions not implemented in this context
代码:SOCbySPKF-CapstoneProjectPart2.m
2.内嵌函数
octave官方的解释:Nested Functions
例子:
function y = foo ()
x = 10;
bar ();
y = x;
function bar ()
x = 20;
endfunction
endfunction
foo ()
⇒ 20
3.解决方式
出现问题的原因在于:内含内嵌函数的函数必须作为一个函数文件,不能写在脚本里。下面例子中,前者报错,后者不报错。
clear -all;
clc;
function test
function nested1
disp('nested 1')
end
function nested2
disp('nested 2')
end
nested1
nested2
end
function test
function nested1
disp('nested 1')
end
function nested2
disp('nested 2')
end
nested1
nested2
end