Command syntax for functions inside packages

조회 수: 3 (최근 30일)
Duc Le
Duc Le 2022년 1월 13일
답변: Bala Tripura Bodapati 2022년 2월 3일
Matlab has a "command syntax" where if you call a function without brackets the arguments are passed as character arrays to the called function, e.g.
help topic
is interpreted as
help('topic')
But this doesn't seem to work when the function is inside a +package folder - e.g. If I have
+mypack
|--myfunc.m
and I call
mypack.myfunc some arguments
This fails with:
mypack.myfunc some arguments
Error: Invalid expression. Check for missing multiplication operator, missing or unbalanced delimiters, or other syntax error. To construct matrices, use brackets
instead of parentheses.
However, if I import the function it works fine, e.g.
import mypack.myfunc
myfunc some arguments
So the question is: Is command syntax supported for functions inside packages (without using import)? If so, how do I get it to work?

채택된 답변

Bala Tripura Bodapati
Bala Tripura Bodapati 2022년 2월 3일
Hi Duc Le,
It is my understanding that command syntax is working fine when importing the package and then calling the function. But calling the function using the fully qualified signature is giving an error. Currently we are not supporting this feature.I have brought this issue to the notice of concerned people and it might be considered for future releases.
A possible workaround I would like to suggest is to make the package a normal folder and add it to the MATLAB path. With this approach, you can directly call the function using command syntax.
The following is the link to documentation of “addpath” to add the folder to the MATLAB path:

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Get Started with MATLAB에 대해 자세히 알아보기

제품


릴리스

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by