Create a function - with cross reference

조회 수: 3 (최근 30일)
Matrix-Matlab
Matrix-Matlab 2017년 5월 28일
답변: Guillaume 2017년 5월 28일
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

답변 (1개)

Guillaume
Guillaume 2017년 5월 28일
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')

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by