why do I receive not enough input arguments

20 次查看(过去 30 天)
That's my code and I keep receiving "not enough inpur arguments" error in line 11
function [y] = signal_avg_lim( filename, peaknumber, revsize )
%SIGNAL_AVG function for averaging x number of peaks for a signal
%Discription: The user inputs the filename of interest and the number of
%peaks that the data is to be averaged over. For each revolution the signal
%is averaged over the x max peaks. The averaged data for each revolution is
%then plotted.
%Currently only works for 10 revs
revstart = 000001;
counter = 1;
11. revincrease = revsize;
%Loop to run for 10 revs
%removing outliers
revsize = revsize + revstart;
y = zeros(10, 1);
DiffYSqt = zeros(10, 1);
x = 1:10;
while counter < 11
[pks, locs] = findpeaks(filename.(1)(revstart:revsize),'MinPeakHeight',10);% returns the indices of the peaks
i= 1;% initializes the counter
pks = pks';% inverts the pks array
[r, c] = size(pks); % provides the row and colum size for the pks array
while i < r-1
i = i + 1;
if pks(i)> 1000
pks(i) = 0;
end
%if pks(i)> (pks(i+1)+ 50)
% pks(i) = 0;
%end
end
pkssort = sort(pks, 'descend');
topx = (pkssort(1:peaknumber));
pnt1 = mean(topx);
counter2 = 1;
while counter2 < (peaknumber+1)
DiffYSqt = (topx(1,counter2) - pnt1)^2;
counter2 = counter2 +1;
end
mean2 = mean(DiffYSqt);
std (counter, 1) = sqrt(DiffYSqt);
y(counter, 1) = pnt1;
revstart = revsize;
revsize = revsize + revincrease;
counter = counter +1;
end
%print the results
x;
y;
%Plot
plot (x, y, 'o');
ylim([0 800]);
%lsline
end
  2 个评论
Torsten
Torsten 2023-2-16
编辑:Torsten 2023-2-16
And how do you call the function ?
If you don't supply input arguments, you'll get the message "not enough input arguments". Sounds logical.
And the line
11. revincrease = revsize;
will throw an error.
Omar
Omar 2023-2-17
I'm new to matlab and I never used any coding software before so I think I'm using three inputs I ran the code signal_avg_limt "(Dec20-1(cut4&2)_filter, 50, 094167" and then the error pops up like that
" Not enough input arguments.
Error in signal_avg_lim (line 11)
revincrease = revsize; "

请先登录,再进行评论。

回答(2 个)

Steven Lord
Steven Lord 2023-2-16
Based on the function definition:
function [y] = signal_avg_lim( filename, peaknumber, revsize )
your function can accept a maximum of three input arguments. Since the code does use the revsize variable in the body of the function (on the line revincrease = revsize;) your function needs to be called with at least three input arguments. Therefore you must call it with exactly three input arguments.
From the text of the error message you're likely calling it with fewer than three input arguments.
If you are calling it with exactly three inputs, please show us how you're trying to call signal_avg_lim and show us the output of the following function call executed immediately before you call signal_avg_lim.
whos
  2 个评论
Omar
Omar 2023-2-17
I'm new to matlab and I never used any coding software before so I think I'm using three inputs I ran the code signal_avg_limt "(Dec20-1(cut4&2)_filter, 50, 094167" and then the error pops up like that
" Not enough input arguments.
Error in signal_avg_lim (line 11)
revincrease = revsize; "
Steven Lord
Steven Lord 2023-2-18
Is this exactly what you typed in the Command Window or the script where you're trying to run this code?
signal_avg_limt "(Dec20-1(cut4&2)_filter, 50, 094167"
That is equivalent to:
signal_avg_limt("(Dec20-1(cut4&2)_filter, 50, 094167")
which is calling signal_avg_limit with one input argument, the string "(Dec20-1(cut4&2)_filter, 50, 094167". What you're using is the "command form", as described on this documentation page. In general you should only use command form for functions where all the input arguments are text (character vectors or strings.) So functions like help, hold, doc, ls, etc. are all fine to call in command form, but for other functions (like your signal_avg_limit) I recommend using function form.
signal_avg_lim("(Dec20-1(cut4&2)_filter", 50, 094167)
I assume the "t" at the end of your function name was a typo and have omitted it in the function call above.
That file name also looks strange to me; while it's okay for a file name to have mismatched parentheses, it's likely to throw off programmers reading your code.

请先登录,再进行评论。


Jan
Jan 2023-2-17
signal_avg_limt "(Dec20-1(cut4&2)_filter, 50, 094167"
This calls the function with 1 argument: a string. I guess you mean this instead:
signal_avg_limt('Dec20-1(cut4&2)_filter', 50, 094167)
The code looks strange: revstart = 000001 is the same as revstart = 1.
I cnnot guess the purpose of this expression: filename.(1)(revstart:revsize) .
This does not print anything:
%print the results
x;
y;
  5 个评论
Omar
Omar 2023-2-17
@Jan Thank you for replying, I think .(1) is added by mistake, I removed it so the code be (filename(revstart:revsize) I think that's avalid expression.
That file is a text document, it's data (plotted as curves) and I want to make matlab extract the maximum average peaks from the curves.
Jan
Jan 2023-2-18
@Omar: filename(revstart:revsize) is the part of the filename from index revstart to revsize. I'm sure you do not want to process the characters of the file name, but the contents of the file.
I've asked already what kind of file 'Dec20-1(cut4&2)_filter' is. If you answer this question fpr clarification, suggesting a method to import the data is possible.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 RF Blockset Models for Transceivers 的更多信息

产品


版本

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by