Handling data form a table in appDesigner

Hi, I created a table in app designer, this table contains 5 columns (description,mass, x, y, z), i want to display a result (position center of gravity) in a numeric edit field, but i don't know how to manipulate the data from the table to do my calculations. I want to use the second, third, fourth e fifth columns and each row to do my calculus, but i dont't know how to do that in appDesigner.
Thank you!
Marco

4 Comments

Can you provide a little more information about what you would like to do? Would you like to click on a cell and have the values from that row calculate center of gravity? Generally speaking you can just right click on the table in the Design View tab, click Callbacks, and select Add CellEdit Callback (if you want to run a function when a cell is edited).
I created a Table, so the user can add rows in the GUI, each row has 5 columns:
  1. description
  2. mass
  3. x position
  4. y position
  5. z position
i also created a numeric edit field (where i want to display the x position on the center of gravity for example) and a button, when i push the button i want to display in the numeric edit field the value of x position of center of gravity.
To do this i did a callback on the button and i said:
mass_vector = app.UITable.Data{:,2}
x_vector = app.UITable.Data{:,3}
x_cog = sum(mass_vector.*x_vector)/sum(mass_vector)
app.NumericEditField.Value = x_cog
but it doesn't work.
thank you!
Your callback doesn't like your brackets.
%%%% I'm mimicking your table
fig = uifigure;
t = uitable(fig,'ColumnEditable',true,...
'ColumnName',{'description','mass','x','y','z'},...
'Data',rand(5,5));
%%%% The only thing different is that you need to change the brackets, name
%%%% of your table (mine is t, yours is obviously app.UITable), and add
%%%% another . in your x_cog calculation.
mass_vector = t.Data(:,2);
x_vector = t.Data(:,3);
x_cog = sum(mass_vector.*x_vector)./sum(mass_vector);
app.NumericEditField.Value = x_cog;
thank you very much!

Sign in to comment.

Answers (0)

Categories

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

Asked:

on 14 Mar 2021

Commented:

on 17 Mar 2021

Community Treasure Hunt

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

Start Hunting!