フィルターのクリア

not enough input arguments

3 ビュー (過去 30 日間)
Daniela
Daniela 2024 年 4 月 22 日
回答済み: Walter Roberson 2024 年 4 月 22 日
Hello, here is my simple equation of a function to determine total pay after taxes. I'm new to Matlab and i'm getting an error in line 5 but im not really understanding why.
-------------------------------------------------------------------------------------
function [takehome_pay, taxes_paid, total_pay] =
PaycheckFunction(HoursWorked, HourlyWage, TaxRate)
end
% Function to determine your take home pay after taxes are taken out
total_pay = HoursWorked * HourlyWage;
taxes_paid = total_pay * TaxRate;
takehome_pay = total_pay - taxes_paid;
Not enough input arguments.
Error in PaycheckFunction (line 5)
total_pay = HoursWorked * HourlyWage;

回答 (2 件)

Cris LaPierre
Cris LaPierre 2024 年 4 月 22 日
It looks like the end is in the wrong place. Move it to the bottom of your function.
function [takehome_pay, taxes_paid, total_pay] = PaycheckFunction(HoursWorked, HourlyWage, TaxRate)
% Function to determine your take home pay after taxes are taken out
total_pay = HoursWorked * HourlyWage;
taxes_paid = total_pay * TaxRate;
takehome_pay = total_pay - taxes_paid;
end

Walter Roberson
Walter Roberson 2024 年 4 月 22 日
You are trying to run the function by pressing the green Run button. When you run the function by pressing the green Run button, the function is executed with no parameters.
MATLAB will never go searching in the environment to try to find values for variables that are named as parameters on the function line. You always have to supply any necessary values when you call the function.
Go down to the command line and invoke the function passing in appropriate values.

Community Treasure Hunt

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

Start Hunting!

Translated by