Undefined function for input arguments of type 'matlab.ui​.control.N​umericEdit​Field' & 'matlab.ui​.control.S​tateButton​' using app designer

86 次查看(过去 30 天)
Hello,
I am having issues programmatically adding componenets to my app designer code and then writing a callback function for the changing of those values (while outside of the creation function, read below).
I have 2 instances of this issue. I will try to make it clear how I receive ther error.
CASE 1:
I programmatically generate NumericEditField components and have a function that is outside of the generation function. e.i.
% Creation function for numelements number of edit boxes and buttons
function createCH_Freq_Edit_Fields(app,app.numelements) %app.numelements is a user input. We generate that many edit fields & buttons
%generate ui.buttons according to numelements
for CH = 1:numelements
% Create CH#EditField
app.CH_Freq_Edit_Fields(CH) = uieditfield(app.CHPanel, 'numeric');
% Change other parameters like Position, etc. with the "set(app.CH_Freq_Edit_Fields(CH),'Parameter',value');" form
% change variables in @app.CHFreqChange function if editfield is changed
set(app.CH_Freq_Edit_Fields(CH),'ValueChangedFcn',@CH_FreqsChanged);
end
end %of createCH_Freq_Edit_Fields
% Value changed function: CH_FreqsChanged
function CH_FreqsChanged(app,event)
for CH = 1:app.numelements
app.Freq_values = get(app.CH_Freq_Edit_Fields(CH),'Value');
end
% ****Use this vector (app.Freq_Values) in another function
end %of CH_Freqs
I get an error however. The error is: "Undefined function 'CH_FreqsChanged' for input arguments of type 'matlab.ui.control.NumericEditField'."
CASE 2:
I programmatically generate StateButton components and have a function that is outside of the generation function. e.i.
%% Buttons for Channel Selection
function createCH_Select_Plot(app,app.numelements)
for CH = 1:app.numelements
CHSelectW(CH) = uibutton(bgWave,'state'); %no need to make this a property in the above code. It is used only in this function.
% Change other parameters like Position, etc. with the "set(CHSelectW(CH),'Parameter',value');" form
CHSelectW(CH).ValueChangedFcn = @CHButtonValueChanged;
end
end %of createCH_Select_Plot
% Value changed function: CHButton
function CHButtonValueChanged(app,event)
for i = 1:numelements
CHSelection(1,i) = CHSelectW(i).Value; %check values of W tab selections
CHSelectionSUM(i) = sum(CHSelection(:,i));
%check and change buttons if one tab is changed
if CHSelectionSUM(i) == 1 || CHSelectionSUM(i) == 3 %check to see which are "on" (==1 just turned on for first time, ==3 turned on already, keep on)
%do something if "on"
elseif CHSelectionSUM(i) == 2 || CHSelectionSUM(i) == 0 %check to see which are "off" (==2 just turned off, ==0 was already off)
%do something else if "off"
end
end
end %of CHButtonValueChanged
Here, I return an error "Undefined function 'CHButtonValueChanged' for input arguments of type 'matlab.ui.control.StateButton'."
Question:
Question is, how do I fix this? I have seen my callbacks work if I place the ValueChangeFcn inside of the creation function, but then these functions are not referencable in other functions later on. I would like to have other functions change the values and execute the callbacks programmatically.
How can I rewrite these functions to receive these ui components as inputs?
P.S. I am using Matlab 2019b Update 4 and working exclusively in App Designer. NOT GUIDE. I have a long list of functions in conjunction with app designer made functions in my app. It would be best if we can make it work on this platform, not GUIDE.
Thanks in advanced!

采纳的回答

Caleb Wilkins
Caleb Wilkins 2020-3-10
编辑:Caleb Wilkins 2020-3-10
I've found the answer from MathWorks support. He said,
"I think the issue is that you're structuring the "ValueChangedFcn' incorrectly for line 150. I got it to work by doing the following:
app.CH_Freq_Edit_Fields(CH) = uieditfield(app.CHPanel,'numeric','ValueChangedFcn', @(txt,event) CHFreqsChanged(app,event));
Now, when you change the frequency the app successfully enters the "CHFreqsChanged" function.
Here is how you should generally structure a callback fro a "uieditfield".
As for the I/O button issue, there is a similar fix. On line 226:
set(app.CH_IO(CH),'ValueChangedFcn', @(btn,event) CH_IOChangeValueFcn(app,event));
Here is how to set a callback for a "uibutton"."
I missed those tiny little
lbl and
btn
pieces in the callbacks!

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Develop Apps Using App Designer 的更多信息

产品


版本

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by