Define Matrix array as a function
Show older comments
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.
Accepted Answer
More Answers (1)
Cam Salzberger
on 19 Oct 2017
Edited: Cam Salzberger
on 19 Oct 2017
Hello Marzieh,
It seems like there may be a relatively fundamental misunderstanding here. Let me see if I can put it clearly.
Numeric arrays: These are simply numbers. These numbers may have meaning that you assign to them, but they don't represent anything by themselves. For example, if you do this:
x = 0:pi/20:2*pi;
ySin = sin(x);
ySinc = sinc(x); % If you have Signal Processing Toolbox
you have now created two numeric arrays. "ySin" doesn't represent that sine function, but it does contain the values gotten by calculating the sine function at each of the points in "x". Similarly for "ySinc".
Symbolic variables and functions: If you are using the Symbolic Math Toolbox, you can create symbolic variables and functions. For example:
syms x
f = sin(x);
Now "f" represents the sine function in a more fundamental way. However, it does not contain any numeric values yet, it is more of an instruction on how to perform the computation. You would compute it with:
subs(f, 0)
to substitute in the value of 0 for "x". You can have arrays of symbolic functions, which will produce array output:
f = [sin(x) cos(x)];
subs(f, pi)
Function handles: Similar to symbolic functions, these are more of instructions on how to perform the computation. However, while the symbolic functions can be used in further symbolic computation, solving, or simplifying, function handles are just instructions on how to run a particular function. That said, you can do something like this:
f = @sin;
Now you have a handle to the numeric sine function in MATLAB. You can compute values like this:
x = 0:pi/20:2*pi;
f(x)
You can have cell arrays of function handles, though it can be confusing trying to evaluate them all at once. Here's a quick example:
f = {@sin @cos};
cellfun(@(h) feval(h, 1), f)
I hope this helps to give you an overview of different "function types" in MATLAB.
-Cam
4 Comments
Marzieh Parsa
on 20 Oct 2017
Cam Salzberger
on 20 Oct 2017
Hello Marzieh,
It seems like Walter's given an answer, though I'm not sure I understand your question fully. What are you expecting the output of "E(j,i)" to be? A numeric datatype or a symbolic expression? A scalar or a vector?
If Walter's answer is what you're looking for, then that's great. If you're looking for something different, can you provide this information?
-Cam
Steven Lord
on 20 Oct 2017
So let's say that you were able to create a matrix A with "all elements are Sinc Function". How would you then try to use that matrix? Don't try to explain it with code or pseudocode; explain it in words as though we were completely unfamiliar with your application (because we are!)
Marzieh Parsa
on 21 Oct 2017
Edited: Marzieh Parsa
on 21 Oct 2017
Categories
Find more on Conversion in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!