matlab code need help to solve it

2 visualizaciones (últimos 30 días)
shoosh omad k
shoosh omad k el 15 de Jun. de 2020
Editada: Shubhankar Poundrik el 22 de Jun. de 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 comentarios
madhan ravi
madhan ravi el 15 de Jun. de 2020
Editada: madhan ravi el 15 de Jun. de 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 el 15 de Jun. de 2020
i just edited the title to be understod

Iniciar sesión para comentar.

Respuestas (1)

Shubhankar Poundrik
Shubhankar Poundrik el 15 de Jun. de 2020
Editada: Shubhankar Poundrik el 22 de Jun. de 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 comentario
shoosh omad k
shoosh omad k el 15 de Jun. de 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 .

Iniciar sesión para comentar.

Categorías

Más información sobre Loops and Conditional Statements en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by