matlab code need help to solve it

1 view (last 30 days)
shoosh omad k
shoosh omad k on 15 Jun 2020
Edited: Shubhankar Poundrik on 22 Jun 2020
Write a Matlab code that determines whether a company ABC has generated profit or loss percent based on the sales and expenses data from the year 2010 to 2019. The fomula to calculate the profit/loss percent is:
Profit/loss (%) =100x(sales-expenses)/expenses
where positive percent means that there is a profit while negative percent indicates a loss and zero percent means no change.
The code should be organised as follows:
  • Write a getData() function that asks the user to input the sales and the expenses data from the year 2010 to 2019 and returns it. (Do NOT use loops)
  • Write a CalculatePercent() function that accepts the sales and expenses data then returns a vector which holds the calculated percent for each respective year. (Do NOT use loops)
  • Write a ProfitOrLoss() function that accepts the percent vector then returns an appropriate description string vector which shows whether there is a profit, a loss or no change in each year. (Do NOT use loops)
  • Write a main script to do the following:
  • Call getData() function to get the company’s sales and expenses data from the user.
  • Call calculatePercent() to find the profit/loss percent values for each year.
  • Call ProfitOrLoss() to appropriate description for each percent value (i.e. profit, loss or no change)
  • Display the company’s data (year, sales, expenses, percent, and description) in a tabular format.
  2 Comments
madhan ravi
madhan ravi on 15 Jun 2020
Edited: madhan ravi on 15 Jun 2020
Anyhow you are going to edit the question once you get the answer saying your professor/lecturer finds out. Why waste your time and others if you are going to do the same as the others?
shoosh omad k
shoosh omad k on 15 Jun 2020
i just edited the title to be understod

Sign in to comment.

Answers (1)

Shubhankar Poundrik
Shubhankar Poundrik on 15 Jun 2020
Edited: Shubhankar Poundrik on 22 Jun 2020
Hi Shoosh,
I understand that you are not sure how to write MATLAB code with multiple functions in one file.
First a function with the same name as the name of the m file needs to be written. This will be the main function. Below this function define all other functions may be defined. The code structure should look something like this:
% Name of file is mainFn.m
function mainFn
% Write code for main function
% Call other function as required
end
function [outputs] = getData(inputs)
% Write code for getData
end
function [outputs] = ProfitOrLoss(inputs)
% Write code for ProfitOrLoss
end
function [outputs] = calculatePercent(inputs)
% Write code for calculatePercent
end
One helper function may be called from another helper function too. All helper functions (getData, ProfitOrLoss, calculatePercent) must be written below main function.
Regards,
Shubhankar
  1 Comment
shoosh omad k
shoosh omad k on 15 Jun 2020
thank you Shubhankar to tell me how to write the functions
now i will try to know how to solve the code .
thank you a lot .

Sign in to comment.

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!