Effacer les filtres
Effacer les filtres

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

1 vue (au cours des 30 derniers jours)
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)
function c = add(n, k)
c = n + k;
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 =
So is this a bug or do I mistake the usage of classes or memoized functions in MATLAB? Any suggestions or solutions are appreciated.

Réponse acceptée

James Lebak
James Lebak le 2 Déc 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 commentaire
James Lebak
James Lebak le 2 Déc 2021
Modifié(e) : James Lebak le 2 Déc 2021
Here is the bug that is the likely culprit.

Connectez-vous pour commenter.

Plus de réponses (0)


En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange




Community Treasure Hunt

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

Start Hunting!

Translated by