Hi folks,
I'm trying to initialise the table values on the app designer to zero, then increment the relevant cell based on specific button clicks.
I'm doing this by making a general function ButtonPressed(), that increments the relevant index value of the array of numbers that populates the table, then having each button calling this function when pressed, but for the index relevant to it.
I'm certain that my syntax is incorrect, but I can't seem to find any documentation on this and would appreciate some help if possible!
Below are my code and a screenshot of the app.
Thanks!
methods (Access = private) function ButtonPushed(app, index) app.dataStructCounts(index) = app.dataStructCounts(index) +1; app.dataStructPercentage(index) = (app.dataStructPercentage(index) / app.TotalCounts) * 100; app.TotalCounts = (app.IncipientCounts + app.CircularCounts + app.LenticularCounts + app.RibbonCounts + app.IsotropicCounts + app.FillerCounts); app.TotalPercentage = (app.IncipientPercentage + app.CircularPercentage + app.LenticularPercentage + app.RibbonPercentage + app.IsotropicPercentage + app.FillerPercentage); app.UITable.Data = [app.dataStructCounts, app.dataStructPercentage]; end end function startupFcn(app) app.dataStructCounts = {app.IncipientCounts; app.CircularCounts; app.LenticularCounts; app.RibbonCounts; app.IsotropicCounts; app.FillerCounts; app.ResinCounts; app.TotalCounts}; app.dataStructPercentage = {app.IncipientPercentage; app.CircularPercentage; app.LenticularPercentage; app.RibbonPercentage; app.IsotropicPercentage; app.FillerPercentage; app.ResinPercentage; app.TotalPercentage}; app.TotalCounts = (app.IncipientCounts + app.CircularCounts + app.LenticularCounts + app.RibbonCounts + app.IsotropicCounts + app.FillerCounts); app.TotalPercentage = (app.IncipientPercentage + app.CircularPercentage + app.LenticularPercentage + app.RibbonPercentage + app.IsotropicPercentage + app.FillerPercentage); app.UITable.Data = [app.dataStructCounts, app.dataStructPercentage]; end function UITableCellEdit(app, event) indices = event.Indices; newData = event.NewData; app.UITable.Data = [app.dataStructCounts, app.dataStructPercentage]; end % Button pushed function: IncipientButton
function IncipientButtonPushed(app, event) ButtonPushed(app, 1); end end
Best Answer