필터 지우기
필터 지우기

Calling a function from within a nested package

조회 수: 1 (최근 30일)
Or Nahir
Or Nahir 2018년 5월 29일
답변: JackXu 2019년 12월 19일
Hi,
I want to build my project in using package. The problem is that I can't use nested packages because of the following problem. Let's assume I want to write package +Add, and than just use it in another package +Math. I started from writing +Add package:
:
function x = add1(x)
x = x+1;
end
add2:
function x = add2(x)
x = Add.add1(Add.add1(x));
end
Now I just add it to +Math package:
>> Math.Add.add1(1)
ans =
2
But:
>> Math.Add.add2(1)
Undefined variable "Add" or class "Add.add1".
Error in Math.Add.add2 (line 2)
x = Add.add1(Add.add1(x));
Any ideas how to solve it or to find a work around that doesn't require changing +Add when I use it in +Math

답변 (1개)

JackXu
JackXu 2019년 12월 19일
I just find we only can use the full package to use the functions.
So add2 need to be like the following:
function x = add2(x)
x = Math.Add.add1(Math.Add.add1(x));
end
I use this method in my project for can't find other way.

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by