2

我想在函数中使用 matlab 函数的根。

但它不起作用。我不知道如何解决这个问题。

这是功能:

function [ roots , poles ] = pr_calc( num , den )
%PR_CALC Summary of this function goes here
%   Detailed explanation goes here


poles=roots([den]);
roots=roots([num]);

end

这是错误消息:

??? At compilation, "roots" was determined to be
a variable and this
 variable is uninitialized.  "roots" is also a
 function name and previous versions of MATLAB
 would have called the function.
 However, MATLAB 7 forbids the use of the same
 name in the same
 context as both a function and a variable.

Error in ==> pr_calc at 6
poles=roots([den]);
4

1 回答 1

4

我认为 matlab 实际上会告诉您您需要知道的一切。您已经定义了一个名为“roots”的变量作为函数的返回值,但“roots”已经一个函数,因此不允许使用相同的名称。试试这个:

function [ myroots , poles ] = pr_calc( num , den )
%PR_CALC Summary of this function goes here
%   Detailed explanation goes here


poles=roots([den]);
myroots=roots([num]);

end
于 2012-10-15T05:48:26.977 回答