How to evaluate different expressions of a matrix for multiple variable values?
3 次查看(过去 30 天)
显示 更早的评论
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 个评论
Stephen23
2015-3-20
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.
采纳的回答
Andrei Bobrov
2015-3-20
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);
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Programming Utilities 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!