need some help with a function and calling it
1 view (last 30 days)
Show older comments
I've come quite far on my script but function and calling them is still hard i was thinking of calling it for an equation, and now I'm tying it out in an if statement before putting it in the loop. The function looks like:
function z = SEKDrive(x,y) %cost for the driving distance
z = 0.17 * x*(y/1000);%nissan leaf e+ 17kwh/100km
end
and the if statment like this:
x = input('How many km is the driving distance? ')
if x > 0 % need to make an && for SOC%
o = SEKDrive(x,SEK_in);
sekleft = SEK_ut - o
else isnan(t2)
disp('number please')
end
However matlab's been telling me its to many input values, and on both the books I have it's kind similar to what i did but it works and mine doesn't.
edited abit late tho
Accepted Answer
More Answers (2)
Ameer Hamza
on 8 May 2020
Edited: Ameer Hamza
on 8 May 2020
SEKDrive have two input arguments. You should pass both.
o = SEKDrive(x, 5); % y=5 for example. You should change it according to your own requirements.
See here for basics of MATLAB functions: https://www.mathworks.com/help/matlab/ref/function.html
0 Comments
Steven Lord
on 8 May 2020
Your function is defined to accept and use two input arguments.
function SEK_ut = SEKDrive(x,y) %cost for the driving distance
You are only specifying one of those input arguments when you call it. [I'm assuming either that your SEKDrive function is defined in a function SEKdrive.m or you're actually calling it in your code as SEKDrive. The case of function and function file names matters in MATLAB.]
o = SEKdrive(x);
What value or values should MATLAB use when the commands inside SEKDrive try to operate on y?
It's as though you asked me "I want you to add two numbers. The first is 3. What's the total?" I don't have enough information to answer the question, and when MATLAB encounters that situation often its response is an error like:
>> plus(3)
Error using +
Not enough input arguments.
To correct the problem, specify a value or a variable for you as the second input when you call SEKDrive or modify the SEKDrive function so it only accepts and uses one input argument.
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!