Why am I getting 'Too many output arguments ' error when using get function?

22 次查看(过去 30 天)
I am writing a program where I access the values from sliders, radio button and process them. I am using callback function for pre-processing and to obtain data. But when I try to access values from outside the functions, I cannot access them and undefined variable error is thrown. If I try using get function , I am getting too many output variables. I am attaching my code and error below
Note : I am using online matlab not the app
function playSong(object,~,varargin)
get(get(rbutton,'SelectedObject'),'String') % This is where I am getting the error
if strcmp(object.UserData,'Original')
fprintf('%s','Hey Original is clicked');
% sldn --> sliders ampn---> amplification
elseif strcmp(object.UserData,'Sample')
selectedOption
else
fprintf('%s','Errors');
end
end
Here rbutton is the button group name and the error I am getting is
Error using rbutton
Too many output arguments.
Error in audioequalizer>playSong (line 201)
get(get(rbutton,'SelectedObject'),'String')
Error using matlab.ui.internal.controller.uicontrol.UIControlController/triggerActionEvent
Error while evaluating UIControl Callback.
Please ignore the varagin argument. If I try to pass the selected value as an argument calulated by another function I am getting
Not enough input arguments.
Error in audioequalizer>playSong (line 200)
value_array
Error using matlab.ui.internal.controller.uicontrol.UIControlController/triggerActionEvent
Error while evaluating UIControl Callback.
Value_array is an input argument consisting of all the slider values. I have initialized it at the start of code as an matrix of size 1*12.
  5 个评论
Stephen23
Stephen23 2024-1-9
编辑:Stephen23 2024-1-9
"Why am I getting 'Too many output arguments ' error when using get function?"
You aren't. The error message tell you where the error occurs:
"Error using rbutton Too many output arguments."
"...I was hoping sliderValues = sliderCallback(source, ~,~) this would allow me to use sliderValues wherever I want but I couldn't"
As addition to dpb's comments: also appreciate that GUIs fundamentally have asychronous code execution. Trying to write GUIs as if they are linear code within which you can simply call a function and get an output ... won't work.
There are several minimal-working examples on this forum for how to use slider callbacks (I know the ones I wrote work), and there are also some popular GUI collections on FEX. Those would be a good foundation for your GUI.
Koushik
Koushik 2024-1-16
Well I did some digging and found what my mistake was and it was exactly what you mentioned , writing my gui linearly anyways now it is working. Thanks guys @dpb @Stephen23

请先登录,再进行评论。

回答(1 个)

dpb
dpb 2024-1-9
移动:dpb 2024-1-9
As noted, you need to start over with trying to write your callback functions -- start by following the defined callback argument protocol; you simply cannot use an interface of your own creation; it MUST follow the defined calling syntax which yours don't. It will never have even a chance to work until you fix that.
From the doc
Program Callback Functions
When you create a callback for a component, App Designer generates a callback function in Code View and places your cursor in the function. Write code in this callback function to program the callback behavior.
Callback Input Arguments
All callback functions that App Designer creates have these input arguments in the function signature:
  • app — The app object. Use this object to access UI components in the app as well as other variables stored as properties.
  • event — An object that contains specific information about the app user's interaction with the UI component.
The app argument provides the app object to your callback. You can access any component (and all component-specific properties) within any callback by using this syntax:
app.Component.Property
See <Simple AppDesigner Example> and follow along how it is done correctly, then follow the model as illustrated.
There's a full chapter in the documentation that explains it all, but you have to take the time to read it and then, once you do, pay attention to it. You can't just freelance it -- won't work.

类别

Help CenterFile Exchange 中查找有关 Prepare Model Inputs and Outputs 的更多信息

标签

产品


版本

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by