필터 지우기
필터 지우기

script file in script file with matlab 2018

조회 수: 1 (최근 30일)
Frederic Coste
Frederic Coste 2018년 8월 22일
댓글: Greg 2018년 8월 22일
Hello
I have 2 script files in the same sub folder.
test.m
function test2
a = 1
b = 2
call_addi
end
function res = addi(x,y)
res = x + y
end
and
call_addi.m
somme = addi(a,b)
If I run 'test' under matlab 2016 everything goes fine. But the same under matlab 2018 gives the following error:
Undefined function or variable 'addi'.
Error in call_addi (line 1) somme = addi(a,b)
Error in test (line 5) call_addi
What shall I do to run these kinds of script under matlab 2018

채택된 답변

Arie Lerner
Arie Lerner 2018년 8월 22일
I am not sure why it works in 2016, but not suppose to, because function addi defined internally inside the file, and should be visible only to functions in this file, not external script. Could be they fixed a bug...
  댓글 수: 2
Arie Lerner
Arie Lerner 2018년 8월 22일
This will fix it:
function test
a = 1
b = 2
addi_ptr = @addi;
call_addi
function res = addi(x,y)
res = x + y
and in call_iddi call:
somme = addi_ptr(a,b)
Greg
Greg 2018년 8월 22일
According to the release notes for R2016b , this was a deliberate change.
"Local functions are visible only to other functions in the same file. Previously, if a function file that defines local functions invoked a script, that script could call those local functions."

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Frederic Coste
Frederic Coste 2018년 8월 22일
Better way is to extrat function addi from test and to create a new addi.m file in the same folder.

카테고리

Help CenterFile Exchange에서 Manage Products에 대해 자세히 알아보기

제품


릴리스

R2018a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by