Syeda
Syeda

Reputation: 341

How to fix input argument error in MATLAB?

I have made the following function to calculate an answer.

function [Calculate]=Cal(x,v1,v2)

x = input( 'Enter Amount=' )
v1 = input( 'Enter Value#1=' )
v2 = input( 'Enter Value#2=' )

c1= 27*(x^2) + -70.21*(x^1);
c2= x^3 + -3*(x^2) + 5*(x^1) + -3.8;
c3 = 20*( x^0.5) + -2.822*( x ) + 87*( x^2);
Calculate= c1*(v1) + c2*(v2)+ c3* (v1*v2)

But in MATLAB editor/command file, i am getting this warning

Input argument 'x' might be unused. If this is OK, consider replacing it by ~.
Input argument 'v1' might be unused. If this is OK, consider replacing it by ~.
Input argument 'v2' might be unused. If this is OK, consider replacing it by ~.

What does it mean. How to fix this error?

Thankyou!!

Upvotes: 0

Views: 4346

Answers (1)

damienfrancois
damienfrancois

Reputation: 59072

if you define Cal like this

function [Calculate]=Cal(x,v1,v2)

you need to call it like this

Cal(1,2,3)

if you want x to be 1, v1 to be 2, etc.

If the function asks the user for the values of x and the others, then those variables should not appear in the function signature and you should have:

function [Calculate]=Cal()

The message says that the value of x given in argument will be unused and overwritten with the one from the user.

Upvotes: 3

Related Questions