I am receiving an error in my script when calling a function.
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
I am getting this error code:
Error using check_inputs
Too many output arguments.
when calling a function I created called check_inputs in the script both of which I have pasted here,
Script:
fprintf('Howdy and welcome to the Turning Circle Maneuver Simulator by Bryce Harris.\n');
fprintf('This program and all of its contents were created by Bryce Harris For Engineering 112 section 539.\n');
fprintf('Bryce Harris created this code with strict adherance to the Aggie Code of Honor:\n');
fprintf('An Aggie does not lie, cheat, or steal, nor tolerate those who do.\n');
fprintf('Please choose an option from below?\n');
fprintf('1) Begin specifying ship parameters to run simulator?\n');
fprintf('2) Terminate the program?\n');
choice = input('Please choose an option:','s')
if ismember(choice,{'1','2'})
switch choice
case '1'
L = input('Please specify the length of your ship in meters:\n')
B = input('Please specify the length of the beam of your ship in meters:\n')
T = input('Please specify the length of the draft of your ship in meters:\n')
C = input('Please specify the block coefficient of your ship:\n')
U = input('Please specify the speed of your ship in meters per second:\n')
S = input('Please specify the rudder angle in degrees(Important counter clockwise is considered positive):\n')
t = input('Please specify the time step size in seconds:\n')
time = input('Please specify the total time of the simulation you desire in seconds:\n')
my_function(check_inputs)
case '2'
fprintf('Program Stopped')
otherwise fprintf('Please choose option 1 or 2.')
end
end
The function I created,
function check_inputs(L,B,T,C,U,S,t,time)
%Checking Length for a postive integer
if (L<0)fprintf('Length must be a positive integer\n')
%Checking Beam for a positive integer
elseif(B<0)fprintf('Beam must be a positive integer\n')
%Checking Draft for a positive integer
elseif(T<0)fprintf('Draft must be a positive integer\n')
%Checking The Block coefficent to confirm positive integer
elseif(C<0)fprintf('Block coefficent must be a positive integer\n')
%Checking to make sure that the speed of the ship is not zero
elseif(U<=0)fprintf('Speed of ship can not equal zero and must be positive\n')
%Checking rudder angle
elseif(S<-40)fprintf('Rudder angle to sharp\n')
elseif(S>40)fprintf('Rudder angle to sharp\n')
%Checking the time interval for test
elseif(t<=0)fprintf('Time intervals must be a positive non-zero integer\n')
%Checking to Time for simulation run request
elseif(time<=0)fprintf('Total simulation time must be a positve non-zero integer\n')
end
%Checking the length to beam ratio
if((L/B)>=4) && ((L/B)<=8)
elseif fprintf('Invalid length by beam ratio when length is divided by the beam the result cannot be less than 4 or more than 8\n')
end
%Checking beam to draft ratio
if((B/T)>=2) && ((B/T)<=4)
elseif fprintf('Invalid beam to draft ratio when the beam is divided by the draft the result must be greater than 2 but less than 4\n')
end
%Checking the block coefficient
if(C>=0.4)&&(C<=1.0)
elseif fprintf('Invalid block coefficient the coefficient must be greater than .4 but less than 1\n')
end
%Checking simulation run time versus time steps requested
if (t>=0)&&(t<=time)
elseif fprintf('Invalid time step to test duration interval the time step interval must be greater than 0 but less than the total simulation time\n')
end
%Checking gravity force
if(0<=(U/sqrt(9.81*L)))&& (0.4>=(U/sqrt(9.81*L)))
elseif fprintf('Invalid gravitational force ratio\n')
end
if ((L/B)>=4) && ((L/B)<=8)&& ((B/T)>=2) && ((B/T)<=4) && (C>=0.4)&&(C<=1.0) && (t>=0)&& (t<=time) && (0<=(U/sqrt(9.81*L)))&& (0.4>=(U/sqrt(9.81*L)))fprintf('Error Code 0: All inputs valid\n')
end
for some reason I think the script is trying to force the choice string into the function which there is no case for I will continue to trouble shoot but I would apperciate some help.
0 Commenti
Risposta accettata
Più risposte (1)
Luna
il 13 Nov 2018
Hi,
While you are calling your function in case ‘1’ you should just call like below:
check_inputs(L,B,T,C,U,S,t,time)
I did not understand why you have written my_function(check_inputs). In this case your function should have a return value.
Return value example:
(so whenever you call this function, it gives you 4 as a result. You can also assign it to a variable)
function returnVariable = check_inputs(L,T,.. etc)
% do some stuff
returnVariable = 4;
end
0 Commenti
Vedere anche
Categorie
Scopri di più su Financial Data Analytics in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!