I keep getting not enough input arguments error when trying to make a sine function

function [x,t] = sin_NU(fs,f0,T)
t = 0:1/fs:T; %time vector
x = sin(2*pi*f0*t); %signal vector
end
I am trying to make a sine function and sample the sine signal with a certain sampling frequency. Please help, I would really appreciate it!

5 comentarios

Dyuman Joshi
Dyuman Joshi el 14 de Abr. de 2022
Editada: Dyuman Joshi el 14 de Abr. de 2022
How are you calling your function? Show the error as well.
Use .* if f0 is not a scalar
Error in sin_NU (line 2)
t = 0:1/fs:T; %time vector
this is the error
[x,t] = sin_NU(1000,10,0.5);
figure(1);
plot(t,x);
xlabel ('Time');
ylabel ('Signal');
title ('sin NU function test');
and this is how I call the function
I am still kind of confused because when I try to run the sin_NU code with values in it, there is a continuous sine signal but not with the sampling frequency (because I think I should get a discrete signal when I run the code, right?) I am not sure if I am doing it right.
I ran your code by just copy pasting and got no error.
I see, thank you! I guess I was too confused. Gotta check on my understanding and also try running the code again ~
Works fine, @kiroro00
[x,t] = sin_NU(1000,10,0.5);
figure(1);
plot(t,x);
xlabel ('Time');
ylabel ('Signal');
title ('sin NU function test');
function [x,t] = sin_NU(fs,f0,T)
t = 0:1/fs:T; %time vector
x = sin(2*pi*f0*t); %signal vector
end

Iniciar sesión para comentar.

 Respuesta aceptada

It's possible that you inadvertently clicked the run button or hit the F5 key in the MATLAB editor window where sin_NU.m was open, which ran the function sin_NU with no input arguments. When that happens, you get the error "Not enough input arguments" on the first line where an input argument is used.
When you run sin_NU with input arguments, as in:
[x,t] = sin_NU(1000,10,0.5);
no error happens because the input arguments are given.
And if you want to see a discrete signal, you may consider using stem instead of plot:
[x,t] = sin_NU(1000,10,0.5);
figure(1);
stem(t,x);
xlim([0 0.06]); % zoom in to show the stems
xlabel ('Time');
ylabel ('Signal');
title ('sin NU function test');

2 comentarios

Thank you! Really sorry for the late reply. I've seen and noted your answer but forgot to respond. Thanks again and have a great day.

Iniciar sesión para comentar.

Más respuestas (0)

Preguntada:

el 14 de Abr. de 2022

Comentada:

el 11 de Dic. de 2022

Community Treasure Hunt

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

Start Hunting!

Translated by