How to create a struct arrary in the app designer.

I am creating a GUI in the app designer, and i have several list box and push button, they are all running based of call backs.
My questions are;
How do you save the inputs from the list boxes and push buttons.
How do create an array that save the information of each user without replacing the previous one
How do you link all the apps so that the infomration from each app is saved in the array

댓글 수: 9

"How do you save the inputs" - saving to a file or to restore the values for the next run?
To create an array, append the new data instead of overwriting them:
S = struct();
for k = 1:5
S(k).value = k;
end
What does "link all the apps" mean?
i have attached a copy of one of my GUIs,
The inputs i am referring to are from a list box or radio button.
I am struggling with getting those inputs saved, so each time a user interacts with app their answers are saved in a struct array.
The app designer you have to create different apps, these are linked to each other, the problem is when you package the apps only the first one is included in the package rather than the others that are also connected with the call backs.
S = struct();
for k = 1:5
S(k).value = k;
end
Also for this code. is k=1:5 refering to the number of trials? or number of users? the app will be ran everytime there is a new user.
Jan
Jan 2022년 11월 11일
"each time a user interacts with app their answers are saved in a struct array" - for which purpose? The data are stored in the GUI already. Is there a benefit to stored them in a struct in addition?
"is k=1:5 refering to the number of trials? or number of users?" - What is a trial? What is a user? You asked for the creation of a struct array and I've posted an example code to create one. I do not know the project you are working in.
Maybe you are using a non-standard definition of "apps".
"i am creating a program in matlab, i am using app designer. there are questions asked in this program and the user has to click either a push button or a list box.
I have created all the interfaces for the user and connected them using call backs in the app designer.
the problems is i cannot figure out how to assign values to list box or radio button, so that i am able to view their selections.
The purpose is to be able to analyze the input for ach user." Just a quick view of what my project is about.
" a non standard definition of apps". i am using the app designer in matlab. my files are save m.lapp. is this a better way to explain it?
sorry i am pretty new user and i am still adapting to the syntax of matlab and computer programming in general.
Jan
Jan 2022년 11월 12일
Your questions are welcome and the purpose of my questions for clarifications is to find a solution for your problem. The terminology is as essential as complicated and misunbderstandings are a typical part of finding a solution.
Are you working with a set of different GUIs? Then "apps" might be the correct term.
"how to assign values to list box or radio button" - Actually the values are set by clicking on the controls.
Thank you so much.
Yes i am working with different sets of GUIs, which are all connected using a call back function. i think its impossible to merge all of these different GUIs into one so i willl just create a folder and upload all of them the in there and run all of them at the same time. instead of just running one and having the others appear.
I have assigned the values, i just cant figure out how to record the response(what values they have selected).
Jan
Jan 2022년 11월 12일
Maybe it is easier to combine the set of GUIs into one GUI with different tabs.
It is not clear, what "record responses" mean. If you click on a GUI element, its value changes automatically. So afterwards you can request the property "Value".
Until now you have explained the purpose of the code by text only. Then an explicit suggestion for a modification of the code is not possible. Answering would be much easier, if you post the relevant part of the code.
"Maybe it is easier to combine the set of GUIs into one GUI with different tabs". How can this be achieved? i have tried including the 2nd GUI into the input argument and that didnt seem to work.
I guess what i want is to be able to have the property value for each GUI update into a matrix i will create.
i have included the code.
classdef Age < matlab.apps.AppBase
% Properties that correspond to app components
properties (Access = public)
UIFigure matlab.ui.Figure
ListBox matlab.ui.control.ListBox
ListBoxLabel matlab.ui.control.Label
NEXTButton matlab.ui.control.Button
TextArea matlab.ui.control.TextArea
TextAreaLabel matlab.ui.control.Label
end
% Callbacks that handle component events
methods (Access = private)
% Code that executes after component creation
function startupFcn(app)
end
% Value changed function: ListBox
function ListBoxValueChanged(app, event)
value = app.ListBox.Value;
if strcmp(app.ListBox.Value ,'18-28')||strcmp(app.ListBox.Value ,'29-39')||strcmp(app.ListBox.Value,'40-50')||strcmp(app.ListBox.Value,'51-61')...
||strcmp(app.ListBox.Value,'62-72');
set(app.NEXTButton,'Enable','on');
end
end
% Button pushed function: NEXTButton
function NEXTButtonPushed(app, event)
Genderpage
app.UIFigure.Visible = 'off'
end
end
% Component initialization
methods (Access = private)
% Create UIFigure and components
function createComponents(app)
% Create UIFigure and hide until all components are created
app.UIFigure = uifigure('Visible', 'off');
app.UIFigure.Color = [0 0 0];
app.UIFigure.Position = [100 100 640 480];
app.UIFigure.Name = 'MATLAB App';
app.UIFigure.Scrollable = 'on';
% Create TextAreaLabel
app.TextAreaLabel = uilabel(app.UIFigure);
app.TextAreaLabel.HorizontalAlignment = 'right';
app.TextAreaLabel.FontWeight = 'bold';
app.TextAreaLabel.Position = [63 444 59 22];
app.TextAreaLabel.Text = 'Text Area';
% Create TextArea
app.TextArea = uitextarea(app.UIFigure);
app.TextArea.Editable = 'off';
app.TextArea.FontName = 'Arial';
app.TextArea.FontSize = 20;
app.TextArea.FontWeight = 'bold';
app.TextArea.FontColor = [0.3922 0.8314 0.0745];
app.TextArea.BackgroundColor = [0 0 0];
app.TextArea.Position = [1 1 640 480];
app.TextArea.Value = {'Please choose an age group. You will be unabe to use the next button untill a selection has been made.'; 'This program doesnt allow the user to see the previous page. '; 'So confirm that input is correct.'};
% Create NEXTButton
app.NEXTButton = uibutton(app.UIFigure, 'push');
app.NEXTButton.ButtonPushedFcn = createCallbackFcn(app, @NEXTButtonPushed, true);
app.NEXTButton.BackgroundColor = [0.3922 0.8314 0.0745];
app.NEXTButton.FontName = 'Arial';
app.NEXTButton.FontSize = 16;
app.NEXTButton.FontWeight = 'bold';
app.NEXTButton.Enable = 'off';
app.NEXTButton.Position = [503 25 112 29];
app.NEXTButton.Text = 'NEXT';
% Create ListBoxLabel
app.ListBoxLabel = uilabel(app.UIFigure);
app.ListBoxLabel.HorizontalAlignment = 'right';
app.ListBoxLabel.FontSize = 18;
app.ListBoxLabel.FontWeight = 'bold';
app.ListBoxLabel.Position = [10 275 75 24];
app.ListBoxLabel.Text = 'List Box';
% Create ListBox
app.ListBox = uilistbox(app.UIFigure);
app.ListBox.Items = {'18-28', '29-39', '40-50', '51-61', '62-72'};
app.ListBox.ValueChangedFcn = createCallbackFcn(app, @ListBoxValueChanged, true);
app.ListBox.FontSize = 18;
app.ListBox.FontWeight = 'bold';
app.ListBox.FontColor = [0.3922 0.8314 0.0745];
app.ListBox.BackgroundColor = [0 0 0];
app.ListBox.Position = [36 148 510 153];
app.ListBox.Value = '18-28';
% Show the figure after all components are created
app.UIFigure.Visible = 'on';
end
end
% App creation and deletion
methods (Access = public)
% Construct app
function app = Age
% Create UIFigure and components
createComponents(app)
% Register the app with App Designer
registerApp(app, app.UIFigure)
% Execute the startup function
runStartupFcn(app, @startupFcn)
if nargout == 0
clear app
end
end
% Code that executes before app deletion
function delete(app)
% Delete UIFigure when app is deleted
delete(app.UIFigure)
end
end
end

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

 채택된 답변

Vijay
Vijay 2022년 11월 14일

0 개 추천

You can use a TabGroup and reposition the TabGroup such that the tab menu bar is out of visual boundary. Like in the following image:
Note: I have not completely hidden the TabGroup just to show you the idea.
If your app is resizable then you must dynamically adjust the position of TabGroup in resize callback of window.
If it is a fixed resolution, then you can fix everything to achieve the above shown layout.
You can use the callback of ‘Next’ and ‘Back’ to switch between tabs.
Hope this helps!

댓글 수: 1

Awesome this helped alot, but the problems seems to be that i am unable to use more than one call back function for the push buttons.
app.TabGroup.SelectedTab = app.AgeTab this seems to be the one working, the one for Gender dosent work at all.
% Callbacks that handle component events
methods (Access = private)
% Callback function: NEXTButton, NEXTButton_4, WelcomeTab
function ButtonPushed(app, event)
app.TabGroup.SelectedTab = app.GenderTab
app.TabGroup.SelectedTab = app.AgeTab
end
% Value changed function: ListBox, ListBox_3, ListBox_4
function ListBoxValueChanged(app, event)
value = app.ListBox.Value;
if strcmp(app.ListBox.Value ,'18-28')||strcmp(app.ListBox.Value ,'29-39')||strcmp(app.ListBox.Value,'40-50')||strcmp(app.ListBox.Value,'51-61')...
||strcmp(app.ListBox.Value,'62-72');
set(app.NEXTButton,'Enable','on');
end
value = app.ListBox.Value;
if strcmp(app.ListBox.Value,'Female')|| strcmp(app.ListBox.Value,'Male')||strcmp(app.ListBox.Value,'Intersex')||strcmp(app.ListBox.Value,'Non-conforming')...
||strcmp(app.ListBox.Value,'Gender-fluid')||strcmp(app.ListBox.Value,'Genderqueer')||strcmp(app.ListBox.Value,'Transgender');
set(app.NEXTButton,'Enable','on');
end % simple loop that allows the push button to stay unable until the person selects an option.
value = app.ListBox.Value;
if strcmp(app.ListBox.Value ,'One')|| strcmp(app.ListBox.Value ,'Two')|| strcmp(app.ListBox.Value ,'Three')...
|| strcmp(app.ListBox.Value ,'Four')|| strcmp(app.ListBox.Value ,'Polygot');
set(app.NEXTButton,'Enable','on');
end

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Develop Apps Programmatically에 대해 자세히 알아보기

질문:

2022년 11월 11일

댓글:

2022년 11월 16일

Community Treasure Hunt

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

Start Hunting!

Translated by