How to evaluate different expressions of a matrix for multiple variable values?
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Lucas Carvalho
le 20 Mar 2015
Commenté : Lucas Carvalho
le 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 commentaires
Stephen23
le 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.
Réponse acceptée
Andrei Bobrov
le 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);
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Characters and Strings dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!