""variable name" was previously used as a variable" error message

1 回表示 (過去 30 日間)
Aaron Friedman
Aaron Friedman 2012 年 12 月 10 日
I keep getting the error message, "Error: "NC" was previously used as a variable,conflicting with its use here as the name of a function or command. regarding the following code I am trying to incorporate within a function:
clear NC;
L1=10; L2=200; u=100; sd=10;
NC=@(x)(1/(sqrt(2*pi)*sd)).*exp((-(x-u).^2)./(2*sd.^2));
P= quadl(@NC,L1,L2);
How do I fix this?
Thanks

回答 (1 件)

owr
owr 2012 年 12 月 10 日
The problem is in your call to "quadl", you dont need the "@" sign. NC is a function handle, not a function, so you dont need the "@":
clear NC;
L1=10; L2=200; u=100; sd=10;
NC=@(x)(1/(sqrt(2*pi)*sd)).*exp((-(x-u).^2)./(2*sd.^2));
P= quadl(NC,L1,L2);

カテゴリ

Help Center および File ExchangeNumerical Integration and Differentiation についてさらに検索

タグ

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by