Error (( Not enough arguments))

2 views (last 30 days)
Melika Eft on 11 Mar 2023
Answered: Walter Roberson on 11 Mar 2023
Hello , I just wrote this code and it gives me that error at line ( N=length (x))thank you indeed
function y = myhilbert(x)
% Compute the Hilbert transform of x using the Fourier transform method.
% Source: https://en.wikipedia.org/wiki/Hilbert_transform#Discrete-time_Hilbert_transform
N = length(x);
X = fft(x);
if mod(N, 2) == 0 % even-length case
h = [1, 2*ones(1, N/2-1), ones(1, 2)];
else % odd-length case
h = [1, 2*ones(1, (N-1)/2)];
end
Y = h .* X;
y = ifft(Y);
end
2 CommentsShow NoneHide None
dpb on 11 Mar 2023
I tried to format the code; not positive it's identical to your posted; the editor keeps inserting comments superficiously when try to break lines but it looks like a reasonable approximation anyway. Use the "Code" button to format your code going forward and make any fixes needed above.
You'll have to show us the code you tried to run, the message in isolation would not seem to apply to the above code.
You're also going to have a problem in the assimilation of the h vectors, you try to catenate a row vector column vectors of differing heights; you'll need to create a column vector instead; use the ";" operator instead of the "," inside the brackets.
Walter Roberson on 11 Mar 2023
ones(1, something) is a single row, so all of the entries in the [] are one row tall and different columns wide. Using , between the parts is fine for that.

Sign in to comment.

Answers (1)

Walter Roberson on 11 Mar 2023
You tried to run the code by pressing the green Run button. When you press the Run button, the function is run without any inputs.
The will never look inside the calling environment or the base workspace to try to find a value for a named parameter that was not passed in at run time.
0 CommentsShow -2 older commentsHide -2 older comments

Sign in to comment.

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!