Code suggestion missing for methods using argument validation

3 Ansichten (letzte 30 Tage)
Christoph Harrer
Christoph Harrer am 16 Sep. 2022
Beantwortet: Deepak am 6 Aug. 2024
  • 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

Antworten (1)

Deepak
Deepak am 6 Aug. 2024
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 –

Kategorien

Mehr zu Argument Definitions finden Sie in Help Center und File Exchange

Produkte


Version

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by