The function may be unused
12 次查看(过去 30 天)
显示 更早的评论
I'm now learnign to use MatLab and I'm not sure where I went wrong.
function ave=myaverage(x,N)
sizex=size(x);
sizeN=size(N);
if sizex(2)>sizeN(2)
beep
disp('Error')
else
total=sum(N);
s=x.*N;
ave=sum(s)/total
end
end
I encounter several errors when creating the finction:
- The function "myaverage" may be unused
- unable todefine the local function "myaverage" because it has the same name as the file.
Also when calling the function, i encountered as error:
i. Function with duplicate name "myaverage" cannot be defined.
采纳的回答
Ameer Hamza
2020-5-1
编辑:Ameer Hamza
2020-5-1
In MATLAB a file containing function definition cannot contain any other line of code before
function ...........
so remove the line
clc; clear all
from the top of the file myaverage.m. It confuses the MATLAB; this innocent-looking line causes both errors and the warning. Remove it, and all the errors will be resolved
2 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Manage Products 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!