Code suggestion missing for methods using argument validation
2 次查看(过去 30 天)
显示 更早的评论
- When using argument validation I am missing the code suggestions for my objects (only for the methods using the "arguments" key word)
- If argument to end block is commented, code suggestion for the method works again
- I was not able to find any topics online where code suggestions where missing
This here shows a test class + the command line output showing the missing code suggestion for the method although it can be accessed
- Is there any way to fix this? Code completion is a very important feature
- I know i could use standard and custom validation functions instead, but i really like the readability of arguments block
- I have not tried custom code completion .json in this case because I want to avoid the effort in general
0 个评论
回答(1 个)
Deepak
2024-8-6
Hi Christoph Harrer,
To my understanding, you are facing the “code suggestions” issue in the command window of MATLAB while using “argument validation” block in the MATLAB class.
I tried reproducing the same in MATLAB R2019b version, and it worked fine with proper code suggestions. I also tried reproducing it in MATLAB R2024a version, there as well it displayed code suggestion correctly.
To fix this issue, you can update your MATLAB to R2019b or later versions, this will resolve the issue.
Attaching the MathWorks official website URL to download the newer version of MATLAB –
A possible workaround to solve this issue can be writing “custom validation methods” which will then display the code suggestions correctly in command window.
Here is a MATLAB Class with “custom argument validation” for your reference –
classdef TestClass
properties
Value
end
methods
function obj = TestClass(val)
if nargin > 0
obj.Value = val;
end
end
function result = addValue(obj, increment)
% Perform input validation manually
if ~isscalar(increment) || ~isnumeric(increment) || increment <= 0
error('Increment must be a positive scalar number');
end
result = obj.Value + increment;
end
function result = multiplyValue(obj, factor)
result = obj.Value * factor;
end
end
end
Attaching the documentation of “Function Argument Validation” as well for reference –
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Argument Definitions 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!