How to evaluate different expressions of a matrix for multiple variable values?
2 views (last 30 days)
Show older comments
Lucas Carvalho
on 20 Mar 2015
Commented: Lucas Carvalho
on 20 Mar 2015
Hi guys, I have a little problem using the eval/feval function... I have a vector/matrix whose rows contain symbolic functions, which are dependent on time. I want to evaluate these values for different time values. The code is below:
r1 =
e*cos(omega*t)
e*sin(omega*t)
0
e = 50;
omega = 20;
t=0:0.001:10;
r1_final = feval(r1,t)
So I gave "e" and "omega" arbitrary values (50 and 20) and also t=0:0.001:10. Using the command bellow I get this error:
"Error using feval Argument must contain a string or function_handle."
How can I transform each row into a function_handle and t to a string?? Thank you!
2 Comments
Stephen23
on 20 Mar 2015
Avoid using feval and eval for such trivial code as this. Learn about anonymous functions and using function handles instead: your work will be much more reliable, be easier to debug and it lets you use the inbuilt code-hinting and code-checking tools. eval and feval are best avoided, and certainly should not be your "standard tool" for basic code like this.
Accepted Answer
Andrei Bobrov
on 20 Mar 2015
r1 = @(t,e,omega)[e*[cos(omega*t);e*sin(omega*t)];zeros(1,numel(t))];
e = 50;
omega = 20;
t=0:0.001:10;
out = r1(t, e, omega);
More Answers (0)
See Also
Categories
Find more on Characters and Strings 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!