I want to use the matlab function roots in a function.
But it doesn’t work. I have no idea how to solve that problem.
Here is the function:
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
And this is the error message:
??? 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]);
I think matlab is telling you everything you need to know, actually. You have defined a variable called “roots” as the return value from your function, but “roots” is already a function, so you are not allowed to use the same name. Try this: