How to sum a specific column in the UI Table Component using MATLAB App designer?

8 views (last 30 days)
How to calcualate the sum of a specified column with a UI table Componment in MATLAB Appdesinger. The UI table is integrated with the struct function to store the data. Please see the attached code file to see the approached taken. Firstly the user enters the two values by clicking the submit button and storing it into the UI table. The user then should beable to press the display button to see the total of a specific colum when chosen from the drop down menu component. Any assistance would be appreciated.

Accepted Answer

Kevin Holly
Kevin Holly on 4 Apr 2022
Please see the edited app attached.
I changed the following functions:
function tablefcn(app)
% d2struct = struct('num',app.num1,'num2',app.num2);
% dg1 = struct2cell(d2struct);
app.UITable.Data = [app.t1;[app.num1,app.num2]];%dg1'];
app.t1 = app.UITable.Data;
end
function sumvalue1(app) % function to sum the columns
app.total = sum(app.t1);
app.TotalEditField.Value= app.total(1);
end
function sumvalue2(app)
app.total = sum(app.t1);
app.TotalEditField.Value= app.total(2);
end
I also deleted a space in your dropdown box for 'Value 1', it was 'Value 1 '. The space was causing the case to not be identified.

More Answers (0)

Categories

Find more on Develop Apps Using App Designer in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!