Error using table: all variables must have the same number of rows

25 visualizaciones (últimos 30 días)
Eli Blumen
Eli Blumen el 4 de Jul. de 2020
Comentada: dpb el 8 de Jul. de 2020
Trying to make an app that does some business and payroll functions, relevant parts are as follows:
Properties
% Payroll
MonthlySalary = {12500};
Tax_Rates = {0.015,0.0505,0.062,0.0145};
Withholding_Rates = {187.5,631.25,775,181.25};
Withholding_Federal = {187.5};
Withholding_State = {631.25};
Withholding_SocialSecurity = {775};
Withholding_Medicare = {181.25};
DatePaid = {};
Employee = {};
Disbursment = {};
Disbursment_Total = {};
Withholding = {};
Withholding_Total = {};
Bounce = {};
functions
function PayrollPayments = PayrollPayments(app)
PayrollPayments = table(app.DatePaid, ...
app.Employee, ...
app.Disbursment, ...
app.Withholding, ...
app.Disbursment_Total, ...
app.Withholding_Total);
end
function PayrollEvents = PayrollEvents(app)
PayrollEvents = table(app.MonthlySalary, ...
app.Bounce, ...
app.Withholding_Federal, ...
app.Withholding_State, ...
app.Withholding_SocialSecurity, ...
app.Withholding_Medicare, ...
app.Disbursment);
end
% Button pushed function: PayrollButton
function PayrollButtonPushed(app, event)
app.Tab.Title = 'Payroll Payments';
app.UITable.Data = PayrollPayments(app);
app.UITable.ColumnName = {'DatePaid','Employee','Disbursment','Withholding','Total Payroll Expenses','Total Withholding'};
app.Tab2.Title = 'Payroll Events';
app.UITable2.Data = PayrollEvents(app);
app.UITable2.ColumnName = {'Monthly Salary','Bounce','Federal Tax','State Tax','Social Security Tax','Medicare Tax','Amount Paid'};
Some investigation indicates that I may be causing the issue by mixing column and row variables when creating the table using payroll events. Could it be because I am declaring the variables as individual properties? If I leave out the variables, the table gets created without problem based on the column names.
I am not terribly great at programming, and this is my first time using the app builder - so I am quite stumped. I wanted to solve this problem before moving on to my issues with using tables that reference calculations performed using functions.
  8 comentarios
Eli Blumen
Eli Blumen el 7 de Jul. de 2020
Figured out I had to have the property referenced in the function aready formatted in an array, rather than having the function construct a table out of multiple properties. However, this means that it is perceived as one variable, so only one Column Name will be labled despite there being multiple columns in the table! Any suggesions on how to fix this?
dpb
dpb el 7 de Jul. de 2020
Again, show code -- you can certainly add to an existing table by row for each variable; in fact, that's the only way you can --there has to be a 1:1 correspondence to existing variables.
Just finished answering the "how" of that here -- mayhaps this will help you, as well <Answers/560489-adding-additional-data-to-previous-table>

Iniciar sesión para comentar.

Respuestas (1)

Eli Blumen
Eli Blumen el 8 de Jul. de 2020
properties (Access = public)
% Employees
% EmployeeVars = {'Last Name' 'First Name' 'Address Line 1' 'Address Line 2' 'City' 'State' 'Zip Code' 'Social Security #' '# of Withholdings' 'Yearly Salary'};
Employees = {'Doe','John','Address 1','Address 2','Waltham','MA','02452','280-663-9941',0,'150000.00'};
NewEmployees = {};
% EmployeeLastName = {'Doe'};
% EmployeeFirstName = {'John'};
% EmployeeAddressLine1 = {'Address 1'};
% EmployeeAddressLine2 = {'Address 2'};
% EmployeeCity = {'Waltham'};
% EmployeeState = {'MA'};
% EmployeeZip = {'02452'};
% SocialSecurityNumber = {'280-663-9941'};
% Number_of_Withholdings = {0};
% YearlySalary = {'15000'};
EmployeeList = {};
% NewEmployee ={};
function Employees = EmployeeTable(app)
% Employees = table(app.EmployeeLastName,app.EmployeeFirstName,app.EmployeeAddressLine1,app.EmployeeAddressLine2,app.EmployeeCity,app.EmployeeState,app.EmployeeZip,app.SocialSecurityNumber,app.Number_of_Withholdings,app.YearlySalary);
Employees = table(app.Employees);
% writetable(Employees,'Employees.csv');
end
function ListEmployeesButtonPushed(app, event)
app.Tab.Title = 'Employees';
app.Tab2.Title = 'N/A';
app.UITable.Data = EmployeeTable(app);
% app.UITable.ColumnName = {'Last Name' 'First Name' 'Address Line 1' 'Address Line 2' 'City' 'State' 'Zip Code' 'Social Security #' '# of Withholdings' 'Yearly Salary'};
The problem is that I need the ability to append the array and have the table update to show the changes. If I have the array being assembled from variables by a function, I am unsure how to either append the variables such that they form columns in the array, or append the array (or its components) when it is controlled by a function. Ideally the function would assemble the array and pass it off to another variable.
  3 comentarios
Eli Blumen
Eli Blumen el 8 de Jul. de 2020
figured it out
app.UITable.Data = table(app.EmployeeLastName,app.EmployeeFirstName,app.EmployeeAddressLine1,app.EmployeeAddressLine2,app.EmployeeCity,app.EmployeeState,app.EmployeeZip,app.SocialSecurityNumber,app.Number_of_Withholdings,app.YearlySalary);
dpb
dpb el 8 de Jul. de 2020
I've never used the UITable -- I presume the above syntax replaces the whole .Data property?
Is there a way to reference a row?

Iniciar sesión para comentar.

Categorías

Más información sobre Develop Apps Using App Designer en Help Center y File Exchange.

Productos


Versión

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by