Indexing a vector function, $E(s)=(E_1(s),E_2(s),E_3(s))$, in MATLAB without evaulating the function

230 Views Asked by At

This is simple, but for some reason I can't find the solution anywhere on the internet. I have a vector function in MATLAB $$E(s)=(E_1(s),E_2(s),E_3(s))$$ I want to be able to index it, so normally in MATLAB you would use 'E(1)', for element one. However this just evaluates the vector at $s=2$. 'E(s)(1)' gives an error, this must be simple, it's ridiculous this is causing a problem.

Any help would be greatly appreciated, here's my code for reference

1

There are 1 best solutions below

0
On BEST ANSWER

Actually you have a symbolic function that returns a vector. Type whos and you'll see that the class of E is symfun. Unfortunately, I don't think that you can directly index into a symbolic function. However, you can convert it into a symbolic expression (class sym) simply by setting it equal to another variable and passing in your symbolic variable s

Es = E(s);

Now you should be able to evaluate Es(1), Es(2), and Es(3) as you wanted.

In the future, this sort of question would probably be better suited for Stackoverflow Matlab.