Wrong varargin when calling memoized functions saved in a handle class as constant properties

조회 수: 1 (최근 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.

채택된 답변

James Lebak
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
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 CenterFile Exchange에서 File Operations에 대해 자세히 알아보기

제품


릴리스

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by