Wrong varargin when calling memoized functions saved in a handle class as constant properties
1 view (last 30 days)
Show older comments
I have a handle class named as "MemoizedFunctionClass" to save all the memoized functions as its constant properties and it is coded in a single file in my work dir, like the following one:
classdef MemoizedFunctionClass < handle
properties (Constant)
MemoizedAdd = memoize(@add)
end
end
function c = add(n, k)
c = n + k;
end
Meanwhile, in the same dir I have a script file in which I want to execute my memoized functions. I find that I cannot execute the memoized function "MemoizedAdd" properly when accessing it directly using class dot notation "MemoizedFunctionClass.MemoizedAdd(1, 1)". It seems that only one argument is passed into that memoized function object (One can enter debug mode to check this) thus triggering an error message saying "Not enough input arguments."
MemoizedFunctionClass.MemoizedAdd(1, 1);
% Error: Not enough input arguments.
But if I first assign the memoized function to an intermediate variable, it works fine:
mAdd = MemoizedFunctionClass.MemoizedAdd;
mAdd(1, 1);
% No error occurs
I also noticed that if I use the dot notation in the command line window, it also works fine:
>> MemoizedFunctionClass.MemoizedAdd(1, 1)
ans =
2
So is this a bug or do I mistake the usage of classes or memoized functions in MATLAB? Any suggestions or solutions are appreciated.
0 Comments
Accepted Answer
James Lebak
on 2 Dec 2021
This is a bug. I see this behavior in R2020b and earlier, but not in R2021a or R2021b. If you can try either of those more recent versions it may help.
1 Comment
James Lebak
on 2 Dec 2021
Edited: James Lebak
on 2 Dec 2021
Here is the bug that is the likely culprit.
https://www.mathworks.com/support/bugreports/2394175
More Answers (0)
See Also
Categories
Find more on File Operations in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!