Error using table: all variables must have the same number of rows
6 views (last 30 days)
Show older comments
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 Comments
dpb
on 7 Jul 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>
Answers (1)
Eli Blumen
on 8 Jul 2020
3 Comments
dpb
on 8 Jul 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?
See Also
Categories
Find more on Data Type Identification 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!