Azzera filtri
Azzera filtri

Create a function - with cross reference

4 visualizzazioni (ultimi 30 giorni)
Matrix-Matlab
Matrix-Matlab il 28 Mag 2017
Risposto: Guillaume il 28 Mag 2017
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

Risposte (1)

Guillaume
Guillaume il 28 Mag 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')

Categorie

Scopri di più su Loops and Conditional Statements in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by