[Appdesigner] table that is calculated by the user input data

7 次查看(过去 30 天)
Hi.
I am going to make an app using Matlab’s app designer.
The app will consist of one NumEditField, two Tables (A, B), one result window, and two buttons (Make Table, Calculate).
First, enter a number in the NumEditField and press the Make Table button, then a 3 x n size table A and a 5 x n size table B should be created.
At this time, the data of tables A and B should be able to be entered by the user.
After the user enters all the data for A and B, when the Calculate button is pressed,
I want the value calculated by the Inout_Function(A_1, A_2, A_3, B_1, B_2,B_3, B_4, B_5) function to be displayed through the result window.
Thank you.

回答(1 个)

prabhat kumar sharma
I understand you are facing the problem with app designer UITable.
And I have have designed a similar solution by keeping your requirement in mind. Please find the stepwise solution below.
  1. Open MATLAB and click on the "App Designer" button in the "APPS" tab.
  2. In the App Designer window, drag and drop the following components from the "Component Library" to the app canvas:
  3. One NumEditField (rename it to "numEditField")
  4. Two Tables (rename them to "tableA" and "tableB")
  5. One Result window (e.g., a TextArea component, rename it to "resultWindow")
  6. Two Buttons (rename them to "makeTableButton" and "calculateButton")
Set the properties of the components as follows:
  • For the "makeTableButton", set the "Text" property to "Make Table".
  • For the "calculateButton", set the "Text" property to "Calculate".
Write the below functionalities according to your requirement.
function MakeTableButtonPushed(app, event)
n = app.numEditField.Value;
app.tableA.Data = zeros(n, 5);
app.tableB.Data = zeros(n, 3);
app.tableA.ColumnEditable = true(1,5);
app.tableB.ColumnEditable = true(1,3);
end
% Button pushed function: calculateButton
function calculateButtonPushed(app, event)
A = app.tableA.Data;
B = app.tableB.Data;
result = Inout_Function(app,A,B);
app.resultWindowTextArea.Value = num2str(result);
end
and we have to add a new private function for the InOut Function you want.
methods (Access = private)
function results = Inout_Function(app,A,B)
temp = sum(A,"all");
results = temp + sum(B,"all");
end
end

类别

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

产品


版本

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by