Is Assignment from symmatrix/symfunmatrix Consistent with Assignment from sym/symfun ?

I've just started using symmatrix and symfunmatrix and noticed a behavior that I don't understand and seems to be inconsistent with sym and symfun.
clear all
syms t
syms zfun(t)
zfun(t) = t;
class(zfun)
ans = 'symfun'
Consider four ways to assign from zfun to a new variable h
h = zfun; class(h), clear h % 1
ans = 'symfun'
h = zfun(t); class(h), clear h % 2
ans = 'sym'
h(t) = zfun(t); class(h), clear h % 3
ans = 'symfun'
h(t) = zfun; class(h), clear h % 4
ans = 'symfun'
Cases 1-4 work as I expect, at least based on experience (not sure what the doc states)
Now try the same thing for assigning from a symfunmatrix
clear all
syms t
zfun = symfunmatrix('zfun(t)',t,[3,1]);
zfun(t) = [t;t;t];
class(zfun)
ans = 'symfunmatrix'
h = zfun; class(h), clear h % 5
ans = 'symfunmatrix'
h = zfun(t); class(h), clear h % 6
ans = 'symmatrix'
h(t) = zfun(t); class(h), clear h % 7
ans = 'symmatrix'
try
h(t) = zfun; class(h), clear h % 8
catch ME
ME.message
end
ans = 'Undefined function 'argnames' for input arguments of type 'double'.'
I was expecting cases 5-8 be analagous with cases 1-4.
But case 7 returns a symmatrix into h, contra to a symfun as in case 3, even though the the LHS of the case 7 assignment has a functional form.
Case 8 throws an error altogether, though the caught message seems irrelevant to whatever the error actually was.
Am I missing something as to expected behavior of cases 7 and 8?
The workaround is to define h(t) before the assignment, but that seems inconsistent the symfun cases.
h = symfunmatrix('h(t)',t,[3,1]);
h(t) = zfun(t); class(h)
ans = 'symfunmatrix'
h(t) = zfun; class(h)
ans = 'symfunmatrix'
FWIW, we can see the true error for case 8 by executing outside of the try/catch construct.
clear h
h(t) = zfun;
Incorrect number or types of inputs or outputs for function argnames.

Error in symbolic.validators.mustBeCompatibleReferenceStruct (line 17)
Yvars = argnames(Y);
^^^^^^^^^^^^^^^^^^^^
Error in indexing (line 260)
S {symbolic.validators.mustBeCompatibleReferenceStruct(S, A)}
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

4 Comments

h(t) = zfun;
It makes sense that an error is generated from that. h(t) attempts to define a symbolic function, symfun, but zfun is a symfunmatrix and those two are not compatible.
I don't understand why it's attempting to define a symfun, and I don't see how that can be gleaned from the error message(s). But assuming that is, in fact, the problem ...
For an assignment:
LHS = RHS
my understanding is that the type of the elements of RHS determines the type of the elements of LHS (even if the LHS elements exist when the assignment is executed, which isn't the case in my examples). More concretely, if we have
clearvars
LHS = computesinglescalar(..)
LHS = computedoubledoublearray(..)
From a user perspective:
As a result of executing the first assignment, LHS is created and is of class(single) with size 1x1.
As a result of executing the second assignment, LHS is reassigned and is now of class(double) with size whatever.
I'm sure that is obvious, but I'm putting it out there explicitly to illustrate my understanding that the RHS is effectively (if not actually) created first and then LHS becomes whatever the rhs is.
For
h(t) = zfun
why doesn't the same logic apply, i.e., evaluate the rhs and assign it to LHS (in this case h(t)). Does the Symbolic stuff work differently in this regard?
In other words, why would it be assumed that h(t) is a symfun before the class of the rhs is known (if that's what's actually happening)?
Any thoughts on Case 7?
h(t) = zfun is defined to be the same as
h = symfun(zfun, t)
but symfun() cannot be applied to a symmatrix
If h(t) = zfun is defined to be the same as h = symfun(zfun,t), then I don't understand why those commands result in different error messages.
Actual error messages from try/catch:
clear all;syms t;zfun = symfunmatrix('z(t)',t,[3,1]);
try,h(t) = zfun;catch ME,ME.message,end
ans = 'Undefined function 'argnames' for input arguments of type 'double'.'
clear all;syms t;zfun = symfunmatrix('z(t)',t,[3,1]);
try,h = symfun(zfun,t);catch ME,ME.message,end
ans = 'Too many input arguments.'
I wonder how "type 'double' " gets involved here. Anyway ...
What the user would typically see.
Interesting to me that the error message for the second case in 2025b has been changed from what it was in 2024a
%Error using symfun (line 139)
%First argument must be a symbolic expression.
IMO, none of the error messages in this thread are actually helpful to the user. In particular, how can two inputs to symfun be too many, when two inputs to symfun is a documented usage?
Upon reviewing the doc, I see now that for symfun
is a documented usage, but symfunmatrix doesn't have an analagous command. So I guess, but I'm not sure, that
h(t) = zfun
is not a defined operation?
Presumably it would be an enhancement request for h(t) = zfun to work for zfun being a symfunmatrix in the same way it works for zfun being symfun, i.e., h(t) is a symfunmatrix in the former and symfun in the latter.
Still don't know what's going on with case 7.
Or maybe I'm missing something unique to the symmatrix/symfunmatrix cases that preclude the desired behavior (well, at least desired by me).

Sign in to comment.

Answers (0)

Products

Release

R2025b

Asked:

on 16 Oct 2025

Edited:

on 17 Oct 2025

Community Treasure Hunt

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

Start Hunting!