Wrong varargin when calling memoized functions saved in a handle class as constant properties
3 ビュー (過去 30 日間)
古いコメントを表示
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 件のコメント
採用された回答
James Lebak
2021 年 12 月 2 日
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 件のコメント
James Lebak
2021 年 12 月 2 日
編集済み: James Lebak
2021 年 12 月 2 日
Here is the bug that is the likely culprit.
https://www.mathworks.com/support/bugreports/2394175
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で File Operations についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!