Error "not enough input arguments"

Hi all, I'm new to MatLab and I copied a function from the website here:
To attempt and solve a problem.
This is my code:
function dc = test(t,c)
k1 = 55.2;
k2 = 30.2;
dc = zeros(3,1);
dc(1) = -k1*c(1)^(1/2)*c(2) - k2*c(3)*c(1)^(1/2);
dc(2) = -k1*c(2)*c(1)^(1/2);
dc(3) = k1*c(2)*c(1)^(1/2) - k2*c(3)*c(1)^(1/2);
options = odeset('RelTol',1e-4,'AbsTol',[1e-4 1e-4 1e-5]);
[T,C] = ode45(@test,[0 1],[0.021 0.0105 0.5],options);
plot(T,C(:,1),'-',T,C(:,2),'-.',T,C(:,3),'.')
The error is:
Error using test (line 5)
Not enough input arguments.
Can anyone help?

3 comentarios

Rohan Shaju
Rohan Shaju el 27 de Mzo. de 2018
Editada: Walter Roberson el 28 de Mzo. de 2018
% Simulate supercontinuum generation for parameters similar
% to Fig.3 of Dudley et. al, RMP 78 1135 (2006)
% Written by J.C. Travers, M.H Frosz and J.M. Dudley (2009)
% Please cite this chapter in any publication using this code.
% Updates to this code are available at www.scgbook.info
n = 2^13;                   % number of grid points
twidth = 12.5;              % width of time window [ps]
c = 299792458*1e9/1e12;     % speed of light [nm/ps]
wavelength = 835;           % reference wavelength [nm]
w0 = (2.0*pi*c)/wavelength; % reference frequency [2*pi*THz]
T = linspace(-twidth/2, twidth/2, n); % time grid
% === input pulse
power = 10000;              % peak power of input [W]
t0 = 0.0284;                % duration of input [ps]
A = sqrt(power)*sech(T/t0); % input field [W^(1/2)]
% === fibre parameters
flength = 0.15;             % fibre length [m]
% betas = [beta2, beta3, ...] in units [ps^2/m, ps^3/m ...]
betas = [-11.830e-3, 8.1038e-5, -9.5205e-8, 2.0737e-10, ...
         -5.3943e-13, 1.3486e-15, -2.5495e-18, 3.0524e-21, ...
         -1.7140e-24];
gamma = 0.11;               % nonlinear coefficient [1/W/m]
loss = 0;                   % loss [dB/m]
% === Raman response
fr = 0.18;                  % fractional Raman contribution
tau1 = 0.0122; tau2 = 0.032;
RT = (tau1^2+tau2^2)/tau1/tau2^2*exp(-T/tau2).*sin(T/tau1);
RT(T<0) = 0;          % heaviside step function
%RT = RT/trapz(T,RT);  % normalise RT to unit integral
% === simulation parameters
nsaves = 200;     % number of length steps to save field at
% propagate field
[Z, AT, AW, W] = gnlse(T, A, w0, gamma, betas, loss, ...
                       fr, RT, flength, nsaves);
% === plot output
figure();
lIW = 10*log10(abs(AW).^2); % log scale spectral intensity
mlIW = max(max(lIW));       % max value, for scaling plot
WL = 2*pi*c./W; iis = (WL>400 & WL<1350); % wavelength grid
subplot(1,2,1);             
pcolor(WL(iis), Z, lIW(:,iis)); % plot as pseudocolor map
caxis([mlIW-40.0, mlIW]);  xlim([400,1350]); shading interp; 
xlabel('Wavelength / nm'); ylabel('Distance / m');
lIT = 10*log10(abs(AT).^2); % log scale temporal intensity
mlIT = max(max(lIT));       % max value, for scaling plot
subplot(1,2,2);
pcolor(T, Z, lIT);          % plot as pseudocolor map
caxis([mlIT-40.0, mlIT]);  xlim([-0.5,5]); shading interp;
xlabel('Delay / ps'); ylabel('Distance / m');
Rohan Shaju
Rohan Shaju el 27 de Mzo. de 2018
Please help.Not enough input arguments error!
Walter Roberson
Walter Roberson el 28 de Mzo. de 2018
What is gnlse ?

Iniciar sesión para comentar.

 Respuesta aceptada

Mischa Kim
Mischa Kim el 23 de Nov. de 2014
Thomson, restructure your code in the following way. Put both functions in the same m-file and save it under the same name as the "main" function, my_ode.m, in this case.
function my_ode()
options = odeset('RelTol',1e-4,'AbsTol',[1e-4 1e-4 1e-5]);
[T,C] = ode45(@test,[0 1],[0.021 0.0105 0.5],options);
plot(T,C(:,1),'-',T,C(:,2),'-.',T,C(:,3),'.')
end
function dc = test(t,c)
k1 = 55.2;
k2 = 30.2;
dc = zeros(3,1);
dc(1) = -k1*c(1)^(1/2)*c(2) - k2*c(3)*c(1)^(1/2);
dc(2) = -k1*c(2)*c(1)^(1/2);
dc(3) = k1*c(2)*c(1)^(1/2) - k2*c(3)*c(1)^(1/2);
end

3 comentarios

Thomson
Thomson el 23 de Nov. de 2014
Thank you! This worked :)
Please help.Not enough input arguments error!
function fixedNormal = surfaceNormalImpl(fixedNormal)
% Use 6 neighboring points to estimate a normal vector. You may use
% pcnormals with customized parameter to compute normals upfront
fixed.Normal = surfaceNormalImpl(fixedNormal,idx);
fixedNormal = [fixed.Normal(validPtCloudIndices), ...
fixed.Normal(validPtCloudIndices + fixedCount), ...
fixed.Normal(validPtCloudIndices + fixedCount * 2)];
end
Walter Roberson
Walter Roberson el 27 de Mzo. de 2020
MATLAB thinks you are trying to run the function by itself without passing in any parameters. You cannot just press the green Run button to run that function: you must pass in a single parameter.

Iniciar sesión para comentar.

Más respuestas (3)

Image Analyst
Image Analyst el 22 de Nov. de 2014

0 votos

You forgot to include the error message - you just snipped out a tiny part of it and did not tell us the crucial parts. Please read this. And include all the red text (not just part of it, so we'll know what line 5 actually is), and tell us how you called this function, for example what values for t and c did you pass in?
By the way, you didn't just click the green triangle without providing any input arguments whatsoever, did you???

5 comentarios

Thomson
Thomson el 22 de Nov. de 2014
Editada: Thomson el 22 de Nov. de 2014
Apologies, I did actually try to click the green triangle that is why I'm getting the error. It's late here, however, I am now experiencing a different error:
Attempted to access c(2); index out of bounds because numel(c)=1.
Error in test (line 10)
dc(1) = -k1*c(1)^(1/2)*c(2) - k2*c(3)*c(1)^(1/2);
I just would like to solve the three eqns simutaneously and then graph the result, which should come out to something like this:
If Ch = C(1), Cm = C(2), and Cx = C(3)
Star Strider
Star Strider el 22 de Nov. de 2014
The code you posted runs for me without error (in R2014b), but gives negative and complex outputs.
There has to be a coding error somewhere. What’s your original system?
Thomson
Thomson el 22 de Nov. de 2014
Editada: Thomson el 23 de Nov. de 2014
I am also running R2014b. My system is as follows.
Image Analyst
Image Analyst el 22 de Nov. de 2014
What did you pass in for c? Evidently you passed in just a single number, not an array, so there is no c(2) or c(3).
Thomson
Thomson el 23 de Nov. de 2014
I've tried some vectors such as
[0 0 0]
and now I'm experiencing this error:
Maximum recursion limit of 500 reached. Use set(0,'RecursionLimit',N) to
change the limit. Be aware that exceeding your available stack space can
crash MATLAB and/or your computer.
Error in odeset

Iniciar sesión para comentar.

Deeksha kaila
Deeksha kaila el 2 de Oct. de 2017
Editada: Walter Roberson el 2 de Oct. de 2017
Hello, I typed a function
Function y=lf(x)
Y=log(1-exp(-1/x))
Bt it displays an error 'Not enough input arguments'. Please help me to run this function.

2 comentarios

You need to invoke the routine at the command line and pass in a value. For example,
lf(2.334320)
Jan
Jan el 2 de Oct. de 2017
@Deeksha kaila: Please do not append a new question to an existing thread. This is the section for answers and such "thread hijacking" confuses the readers. Thanks.

Iniciar sesión para comentar.

Sowmitha Sangi
Sowmitha Sangi el 29 de Nov. de 2020
function F = SpectralFlux(signal,windowLength, step, fs)
signal = signal / max(abs(signal));
curPos = 1;
L = length(signal);
numOfFrames = floor((L-windowLength)/step) + 1;
H = hamming(windowLength);
m = [0:windowLength-1]';
F = zeros(numOfFrames,1);
for (i=1:numOfFrames)
window = H.*(signal(curPos:curPos+windowLength-1));
FFT = (abs(fft(window,2*windowLength)));
FFT = FFT(1:windowLength);
FFT = FFT / max(FFT);
if (i>1)
F(i) = sum((FFT-FFTprev).^2);
else
F(i) = 0;
end
curPos = curPos + step;
FFTprev = FFT;
end

2 comentarios

can anyone help me with this :
error: SpectralFlux
Not enough input arguments.
Error in SpectralFlux (line 2)
signal = signal / max(abs(signal));
Walter Roberson
Walter Roberson el 30 de Nov. de 2020
95% of the time when someone posts something like this, it is because they have pressed the big green Run button to run the code, instead of going down to the command line and invoking the code passing in parameters.
If you press the big green Run button, MATLAB will not look inside the base workspace to find definitions for signal, windowLength, step, or fs: MATLAB relies strictly on the values passed in positionally.

Iniciar sesión para comentar.

Categorías

Preguntada:

el 22 de Nov. de 2014

Comentada:

el 30 de Nov. de 2020

Community Treasure Hunt

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

Start Hunting!

Translated by