Using App Designer to control inputs to an outside .m file - basic control
Mostrar comentarios más antiguos
TL:DR I was handed off code I want to update into an app designer that uses a GUI as inputs to a follow up function and am not grasping how to have the GUI talk to outside code and am asking for help on a basic example.
Background - I know this question has been answered a few times on here. But i am still lost as the examples are a bit to high level for me. I have been using matlab for almost 10 years now but only in the basic editor. Additionally, it is the only coding language I know.
I was handed some code from a previous individual that hand coded a GUI. Example:
Signal_Title = uicontrol(Settings_LP,'Style','text',...
'String','Signal Analysis Setup',...
'Units','normalized',...
'Position',[GUI_Spacing_W,1-(S1B_Title_H+GUI_Spacing_H),S1B_Title_W*2,S1B_Title_H],...
'Fontsize',Main_Title_Font);
% Saving height
height_1 = 1-(S1B_Title_H+GUI_Spacing_H);
etc etc and it goes on for 1000 lines of code to create:

Each checkbox is an initial condition that will be used in a following funciton.
I wanted to update this do app designer and I have been struggling. I was able to build the figure to look exactly the same but I am struggling with getting the outputs to be controlled by the GUI.
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
So I wanted to break this down to a fundamenatals question. I want this check mark to interact with an outside function.
I wrote the worlds simplest code.
function checkboxer(inputArg1)
if inputArg1 == 1;
figure
end
end
The intention was to be when the GUI closes. if the box is checked. just poplulate an emply figure. and if the box is not checked. do nothing. I have been trying to get this moving for almost 3 days but I struggle with undestanding classes, properties, callbacks etc and none of the YT videos or forum posts have helped me brigde the gap.
classdef checkboxtester < matlab.apps.AppBase
% Properties that correspond to app components
properties (Access = public)
UIFigure matlab.ui.Figure
Check1CheckBox matlab.ui.control.CheckBox
end
properties (Access = public)
Check1 = 1; % Description
end
methods (Access = public)
function appdesignfunction(app)
checkboxer(app.Check1)
end
end
% Callbacks that handle component events
methods (Access = private)
% Value changed function: Check1CheckBox
function Check1CheckBoxValueChanged(app, event)
value = app.Check1CheckBox.Value;
if value == 1
app.Check1 = 1;
end
end
end
This is the current appdesigner code. Following along a few of the posts I made the outer function a function in app designer, and then to be honest I dont have a clue how properties work or how to call the section of the value. I have been struggling on this basic case but I feel like if I get it explanded in basic terms I should be able to brigde the gap.
2 comentarios
Rik
el 13 de Jun. de 2023
It clicked for me once I understood that AppDesigner results in a class. Callbacks actually call methods (or embedded functions if you want to make things more difficult), and you can store values you need in private properties. In GUIDE you write a big function. Every callback calls in internal function and you can store values in fields of a struct you save and restore with guidata.
Exporting data once a GUI closes can be a bit tricky, but it can be done with both styles.
Did you come across this thread?
Kyle
el 13 de Jun. de 2023
Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre Creating, Deleting, and Querying Graphics Objects en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!