Create a function - with cross reference
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Hello,
I hope you are able to help me. Im fairly new to Matlab and need some help.
My question is that I have 3 excel sheets that I have imported through xlsread. In 1 document, I have Income (social security number that correlates with income), document 2, I have citizens (Social security number that correlates to name, gender and which region they live in), and the final document I have Taxes (region that correlates to amount of tax you pay)
My issue is that now I have to calculate the paid tax in each region and I dont know how to do so.
I have no idea of what to do, besides that I need to get the region, correlate it to the social security number to finally get the income. Can someone please help me?
Thank you in advance, - Emil
0 comentarios
Respuestas (1)
Guillaume
el 28 de Mayo de 2017
Your question is a bit thin on details (like what format are the inputs in, what it is exactly you want to calculate, etc.). The following should give you an idea of how to do whatever it is you want. Adapt as required:
%demo inputs:
incomes = table((1000:1010)', randi(10, 11, 1)*1e4, 'VariableNames', {'ssn', 'income'})
persons = table((1000:1010)', char(randi(double('az'), 11, 5)), categorical(randi([0 1], 11, 1), [0 1], {'Male', 'Female'}), randi(5, 11, 1), 'VariableNames', {'ssn', 'name', 'gender', 'region'})
taxes = table((1:5)', randi([10 20], 5, 1)/100, 'VariableNames', {'region', 'tax'})
%join tables:
alltaxes = join(join(incomes, persons), taxes)
%sum of income * tax, per region
taxperregion = rowfun(@(income, tax) sum(income .* tax), alltaxes, 'InputVariables', {'income', 'tax'}, 'GroupingVariables', 'region', 'OutputVariableNames', 'totaltax')
0 comentarios
Ver también
Categorías
Más información sobre Logical en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!