MATLAB: Define Matrix array as a function

matrix array

Hi everybody.
Would you please guide me how to define an array of a Matrix as a function? For example how can array or components of a Matrix be a Sinc function?
Thanks in advance.

Best Answer

In basic MATLAB, the closest you can get is to have a cell array of function handles that you would have to access and apply to the inputs. (Or, I suppose, an array of some kind of object oriented objects that you created yourself for this purpose.)
In the Symbolic Toolbox, each element of a symbolic array can be used to store a symbol that is a symbolic function. For example,
syms y(t)
A(t) = [sin(t), sinc(t), y]
A(pi/4)
ans =
[ 2^(1/2)/2, (4*sin(pi^2/4))/pi^2, y(pi/4)]
However, this formation is more
A = symfun([sin(t), sinc(t), y], t)
so you will see that A(t) = [ sin(t), sin(pi*t)/(t*pi), y(t)] where sinc(t) has been evaluated already instead of remaining as an unresolved function call.
If you were to instead use
A = [sin(t), sinc(t), y]
then although you would still see A = [ sin(t), sin(pi*t)/(t*pi), y(t)] looking exactly the same content, the result would not be a symbolic function, and attempting A(pi/2) for example would get you a subscript error.
It is not possible to construct a numeric array in which some of the entries are "macros" like in Excel such that changing other entries in the array would change the calculated result at that location.
Related Question