Indexing a vector function, E(s)=(E_1(s),E_2(s),E_3(s)), in Matlab without evaluating the function

StackOverflow https://stackoverflow.com/questions/18833817

  •  28-06-2022
  •  | 
  •  

Question

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 the first element. However this just evaluates the vector at s equals 2. E(s)(1) also gives an error.

Here's my code for reference.

Était-ce utile?

La solution

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 a new 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.

Autres conseils

If I understand you correctly, your only hope is to use the command "eval." Type "help eval" and see if that's what you need.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top