Can't solve parse error

조회 수: 4 (최근 30일)
Alexis
Alexis 2021년 7월 8일
댓글: Alexis 2021년 7월 8일
I am learning how to use inputParser and am stuck here:
function windowedAudio = windowAudio(audioIn,Fs,varargin)
defaultWin = 4;
defaultThresh = 0.1;
defaultRamp = 30;
defaultLong = 500;
defaultShort = 100;
p = inputParser;
addRequired(p,'audioIn',@isnumeric);
addRequired(p,'Fs',@isnumeric);
addParameter(p,'WindowLength',defaultWin,@checkWinLen);
addParameter(p,'SilenceThreshold',defaultThresh,@checkThresh);
addParameter(p,'RampLength',defaultRamp,@checkRamp);
addParameter(p,'LongSilence',defaultLong,@checkLong);
addParameter(p,'ShortSilence',defaultShort,@checkShort);
parse(p,audioIn,Fs,varargin{:});
end
It seems to run beyond that final line if I call the function with only the required arguments:
windowAudio(speechWav,Fs)
But when I try using one of the optional parameters,
windowAudio(speechWav,Fs,'WindowLength',4)
Error using windowAudio (line 31)
The value of 'WindowLength' is invalid. Not enough input arguments.
I have been Googling forever and can't figure out what I have done wrong. Can anyone with fresh eyes help me here?

채택된 답변

Alek Antic
Alek Antic 2021년 7월 8일
Hi,
I have reproduced your error and have found that your issue is most likely coming from your checkWinLen definition. It seems like it requires more than one argument, which is not allowed in a validation function, as documented here.
  댓글 수: 1
Alexis
Alexis 2021년 7월 8일
Thanks @Alek Antic, I didn't notice that in the documentation. Cheers!

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Argument Definitions에 대해 자세히 알아보기

제품


릴리스

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by