Why is validateattributes returning me a Not enough inputs error only in this context?

I have a class definition called LsqSinusoid(n_samples, f, Fs). The constructor for that class takes three inputs - n_samples, the number of samples to use, f, the frequency of a sinusoid function, and Fs, the sample frequency. I am trying to construct an instance of the class, and am calling
lsqsin = LsqSinusoid(500, 500, 25000).
When I type this into the command line it returns the class with the properties I'd expect it to. Excellent.
When I use this code in a script, it returns an error. The first line of the constructor is
validateattributes(n_samples, {'numeric'}, {'positive', 'scalar', 'integer'}).
This line returns the error
Not enough input arguments.
I tried displaying n_samples before calling validateattributes to see if it gets that far, and it displays 500, then claims that there was an error with my call to disp - again, not enough input arguments.
What am I missing? The function takes three arguments, and I've given it three arguments. Why is it returning me this error in this way?

 채택된 답변

I was assigning the class to a vector in reverse order, using a loop like
for k = 16:-1:1
lsqsin(k) = LsqSinusoid(N_samples, frequencies(k), Fs)
end
When I reversed the order of the for loop, the error went away. I don't know why.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

제품

릴리스

R2020b

질문:

2021년 3월 12일

답변:

2021년 3월 12일

Community Treasure Hunt

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

Start Hunting!

Translated by