How to evaluate different expressions of a matrix for multiple variable values?
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Lucas Carvalho
am 20 Mär. 2015
Kommentiert: Lucas Carvalho
am 20 Mär. 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 Kommentare
Stephen23
am 20 Mär. 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.
Akzeptierte Antwort
Andrei Bobrov
am 20 Mär. 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);
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Characters and Strings finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!