Why does tab completion not work for p-coded function arguments in MATLAB R2020b?

조회 수: 9 (최근 30일)
I am using an "arguments" block to define name-value arguments for a MATLAB function, "myRectangle":
function myRectangle(X,Y,options)
arguments
X double
Y double
options.LineStyle (1,1) string = "-"
options.LineWidth (1,1) {mustBeNumeric} = 1
end
% Function code
...
end
I got "myRectangle" from the "arguments" documentation page:
https://www.mathworks.com/help/releases/R2020b/matlab/ref/arguments.html#mw_c78db305-0136-4d4c-b880-f6615c757d8d
I can use tab completion to complete name-value arguments of "myRectangle" when the function is an M-file:
Alt text: The MATLAB command window while I am calling "myRectangle". The tab complete menu shows "LineStyle" and "LineWidth".
However, when "myRectangle" is a P file, MATLAB finds no completions:
Alt text: The MATLAB command window. The command window shows that "myRectangle" is p-coded, and the tab completion menu shows "No completions found."
How can I modify my P file so that I can use tab completion on its arguments?

채택된 답변

MathWorks Support Team
MathWorks Support Team 2024년 1월 9일
Recommended Workaround
As of MATLAB R2022b, MATLAB can tab-complete arguments for p-coded functions. Upgrade your MATLAB to the R2022b release to enable this enhancement for your workflow.
Alternative Workaround
If you do not wish to upgrade, you can use wrapper M-files as an alternative workaround in MATLAB R2020b. For example, say that you p-code the function "myRectangle" that you had earlier. Then you can write a wrapper function, "myRectangleWrapper":
function myRectangleWrapper(X,Y,options)
arguments
X double
Y double
options.LineStyle (1,1) string = "-"
options.LineWidth (1,1) {mustBeNumeric} = 1
end
% Call the p-coded function with the inputs
myRectangle(X, Y, "LineStyle", options.LineStyle, ...
"LineWidth", options.LineWidth);
end
Then, if you enter the text
>> myRectangleWrapper(1, 1, "Line
at the MATLAB command window, you will be able to find "LineWidth" and "LineStyle" when you press tab.

추가 답변 (0개)

카테고리

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

제품


릴리스

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by