Receiving "too many output arguments" error in this code

I am trying to make a effects panel on Matlab App Designer using switch-case logic in order to check which filters are toggled and which are not.
function applyActiveTransformations(app)
audio = app.origFXAudioData;
for i = 1:length(app.activeTransformations)
switch app.activeTransformations{i}
case 'highpass'
cutoffFreq = (app.FxFs/2) - 100;
normalizedCutoff = cutoffFreq/(app.FxFs/2);
[b,a]=butter(4, normalizedCutoff, ...
'high');
audio = filtfilt(b,a,audio);
case 'lowpass'
cutoffFreq = (app.FxFs/2) - 5;
[b,a] = butter(4, cutoffFreq / (app.FxFs/2), 'low');
audio = filtfilt(b,a,audio) ;
case 'bandpass'
lowCutoff=(app.FxFs/2) - 10;
highCutoff = (app.FxFs/2) - 500;
[b,a]= butter(4, [lowCutoff, highCutoff]/(app.FxFs/2),'bandpass');
audio = filtfilt(b,a,audio);
case 'chipmunk filter'
nsemitones = 9;
audio = shiftPitch(audio,nsemitones);
case 'normalize'
audio = audio/max(abs(audio(:)));
end
end
app.procFxAudioData = audio;
end
Here is the callback function for one of the filters. The others follow the same logic:
function highpassButtonPushed(app, event)
if app.highpassButtonPushed.Value == 1
app.activeTransformations{end+1} = 'highpass';
else
app.activeTransformations = setdiff(app.activeTransformations, {'highpass'},'stable');
end
app.applyActiveTransformations();
end

10 件のコメント

Walter Roberson
Walter Roberson 2024 年 12 月 7 日
Which line is it complaining about, thinking that it has too many outputs ?
Stephen23
Stephen23 2024 年 12 月 7 日
Please show us the complete error message. That means all of the red text.
Ria
Ria 2024 年 12 月 7 日
編集済み: Ria 2024 年 12 月 7 日
Here is the complete error message:
Error using newestAudioProjDec6/highpassButtonPushed
Too many output arguments.
Error in newestAudioProjDec6/highpassButtonPushed (line 1742)
disp(app.highpassButtonPushed.Value)
Error in matlab.apps.AppBase>@(source,event)executeCallback(ams,app,callback,requiresEventData,event) (line 62)
newCallback = @(source, event)executeCallback(ams, ...
Error while evaluating Button PrivateButtonPushedFcn.
Rik
Rik 2024 年 12 月 7 日
That is not the complete message.
Walter Roberson
Walter Roberson 2024 年 12 月 7 日
The implication is that somehow app.highpassButtonPushed has become non-scalar, so app.highpassButtonPushed.Value is structure expansion (or object expansion) resulting in multiple parameters passed to disp()
However: the highpassButtonPushed code that you posted does not contain any disp() in it, so either you did not post the correct code or else the wrong version of the code is (somehow) executing.
Ria
Ria 2024 年 12 月 7 日
編集済み: Walter Roberson 2024 年 12 月 7 日
Here is all of the code related to the FX panel:
properties:
origFxAudioData
procFxAudioData
FxFs
fxAudioPlayer
activeTransformations
function applyActiveTransformations(app)
disp(app.activeTransformations)
audio = app.origFXAudioData;
for i = 1:length(app.activeTransformations)
switch app.activeTransformations{i}
case 'highpass'
cutoffFreq = (app.FxFs/2) - 100;
normalizedCutoff = cutoffFreq/(app.FxFs/2);
[b,a]=butter(4, normalizedCutoff, ...
'high');
audio = filtfilt(b,a,audio);
case 'lowpass'
cutoffFreq = (app.FxFs/2) - 5;
[b,a] = butter(4, cutoffFreq / (app.FxFs/2), 'low');
audio = filtfilt(b,a,audio) ;
case 'bandpass'
lowCutoff=(app.FxFs/2) - 10;
highCutoff = (app.FxFs/2) - 500;
[b,a]= butter(4, [lowCutoff, highCutoff]/(app.FxFs/2),'bandpass');
audio = filtfilt(b,a,audio);
case 'chipmunk filter'
nsemitones = 9;
audio = shiftPitch(audio,nsemitones);
case 'normalize'
audio = audio/max(abs(audio(:)));
end
end
app.procFxAudioData = audio;
end
in the startup fnc:
app.activeTransformations = {};
function highpassButtonPushed(app, event)
disp(app.highpassButtonPushed.Value)
disp(app.activeTransformations)
if app.highpassButtonPushed.Value == 1
app.activeTransformations{end+1} = 'highpass';
else
app.activeTransformations = setdiff(app.activeTransformations, {'highpass'},'stable');
end
app.applyActiveTransformations();
end
% Button pushed function: lowpassButton
function lowpassButtonPushed(app, event)
if app.lowpassButtonPushed.Value == 1
app.activeTransformations{end+1} = 'lowpass';
else
app.activeTransformations = setdiff(app.activeTransformations, {'lowpass'},'stable');
end
app.applyActiveTransformations();
end
% Button pushed function: bandpassButton
function bandpassButtonPushed(app, event)
if app.bandpassButtonPushed.Value == 1
app.activeTransformations{end+1} = 'bandpass';
else
app.activeTransformations = setdiff(app.activeTransformations, {'bandpass'},'stable');
end
app.applyActiveTransformations();
end
% Button pushed function: chipmunkfilterButton
function chipmunkfilterButtonPushed(app, event)
if app.chipmunkfilterButtonPushed.Value == 1
app.activeTransformations{end+1} = 'chipmunk filter';
else
app.activeTransformations = setdiff(app.activeTransformations, {'chipmunk filter'},'stable');
end
app.applyActiveTransformations();
end
% Button pushed function: normalizeButton
function normalizeButtonPushed(app, event)
if app.normalizeButtonPushed.Value == 1
app.activeTransformations{end+1} = 'normalize';
else
app.activeTransformations = setdiff(app.activeTransformations, {'normalize'},'stable');
end
app.applyActiveTransformations();
end
Walter Roberson
Walter Roberson 2024 年 12 月 7 日
For the purposes of testing, on the line before
disp(app.highpassButtonPushed.Value)
insert
HIGHBUTTONPUSHED = app.highpassButtonPushed;
whos HIGHBUTTONPUSHED
and tell us what the result is at the time of the error.
Ria
Ria 2024 年 12 月 7 日
here is the error:
Error using riasupdates/highpassButtonPushed
Too many output arguments.
Error in riasupdates/highpassButtonPushed (line 1742)
HIGHBUTTONPUSHED = app.highpassButtonPushed;
Error in matlab.apps.AppBase>@(source,event)executeCallback(ams,app,callback,requiresEventData,event) (line 62)
newCallback = @(source, event)executeCallback(ams, ...
Error while evaluating Button PrivateButtonPushedFcn.
Walter Roberson
Walter Roberson 2024 年 12 月 7 日
Hmmm, change
HIGHBUTTONPUSHED = app.highpassButtonPushed;
whos HIGHBUTTONPUSHED
to
whos app event
for testing purposes.
At the moment, it appears that app is non-scalar and might possibly not be an app at all.
Ria
Ria 2024 年 12 月 7 日
here is the new error:
To get started, type doc.
For product information, visit www.mathworks.com.
Name Size Bytes Class Attributes
app 1x1 8 riasupdates
event 1x1 8 matlab.ui.eventdata.ButtonPushedData
Error using riasupdates/highpassButtonPushed
Too many output arguments.
Error in riasupdates/highpassButtonPushed (line 1743)
disp(app.highpassButtonPushed.Value)
Error in matlab.apps.AppBase>@(source,event)executeCallback(ams,app,callback,requiresEventData,event) (line 62)
newCallback = @(source, event)executeCallback(ams, ...
Error while evaluating Button PrivateButtonPushedFcn.

サインインしてコメントする。

 採用された回答

Walter Roberson
Walter Roberson 2024 年 12 月 8 日
編集済み: Walter Roberson 2024 年 12 月 8 日

0 投票

You define
function highpassButtonPushed(app, event)
which declares highpassButtoPushed as a function that returns no outputs.
You call
disp(app.highpassButtonPushed.Value)
That asks to invoke the function highpassButtonPushed and return some value from that, and index that output at field Value . But highpassButtonPushed is a function that returns no outputs, so the results of it cannot be processed.
You might possibly be wanting to do
disp(app.highpassButton.Value)

2 件のコメント

Ria
Ria 2024 年 12 月 8 日
When I delete
disp(app.highpassButtonPushed.Value)
I'm still receiving this error.
Error using riasupdates/highpassButtonPushed
Too many output arguments.
Error in riasupdates/highpassButtonPushed (line 1743)
if app.highpassButtonPushed.Value == 1
Error in matlab.apps.AppBase>@(source,event)executeCallback(ams,app,callback,requiresEventData,event) (line 62)
newCallback = @(source, event)executeCallback(ams, ...
Error while evaluating Button PrivateButtonPushedFcn.
Stephen23
Stephen23 2024 年 12 月 8 日
"I'm still receiving this error."
Because you still have the same bug here:
if app.highpassButtonPushed.Value == 1
which should be replaced with this:
if app.highpassButton.Value == 1

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeAudio I/O and Waveform Generation についてさらに検索

製品

リリース

R2023b

質問済み:

Ria
2024 年 12 月 7 日

コメント済み:

2024 年 12 月 8 日

Community Treasure Hunt

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

Start Hunting!

Translated by