필터 지우기
필터 지우기

The function may be unused

조회 수: 12 (최근 30일)
Rovindra Nauth
Rovindra Nauth 2020년 5월 1일
댓글: Ameer Hamza 2020년 5월 1일
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:
  1. The function "myaverage" may be unused
  2. 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.
  댓글 수: 1
darova
darova 2020년 5월 1일
Please attach the code

댓글을 달려면 로그인하십시오.

채택된 답변

Ameer Hamza
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
Rovindra Nauth
Rovindra Nauth 2020년 5월 1일
편집: Rovindra Nauth 2020년 5월 1일
Didn't know that. It works now, thank you.
Ameer Hamza
Ameer Hamza 2020년 5월 1일
I am glad to be of help.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Manage Products에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by