How to create a struct arrary in the app designer.

7 ビュー (過去 30 日間)
Nwasinachi
Nwasinachi 2022 年 11 月 11 日
コメント済み: Nwasinachi 2022 年 11 月 16 日
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 件のコメント
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.
Nwasinachi
Nwasinachi 2022 年 11 月 13 日
"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 日
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 件のコメント
Nwasinachi
Nwasinachi 2022 年 11 月 16 日
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 件)

カテゴリ

Help Center および File ExchangeInteractive Control and Callbacks についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by