why do I receive not enough input arguments

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 Comments

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.
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; "

Sign in to comment.

Answers (2)

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 Comments

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; "
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.

Sign in to comment.

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 Comments

I was running it like I posted it and it gives me that error, however after I changed it to signal_avg_lim('Dec20-1(cut4&2)_filter', 50, 094167) as you mentioned it gave me another error which is
Argument to dynamic structure reference must evaluate to a valid field name.
Error in signal_avg_lim (line 22)
[pks, locs] = findpeaks(filename.(1)(revstart:revsize),'MinPeakHeight',10);% returns the indices of the peaks
Torsten
Torsten on 17 Feb 2023
Edited: Torsten on 17 Feb 2023
You must exactly know which inputs the function you use expects. That means you must know to which variable class they belong and what their dimensions are.
@Omar: As I've guessed already: filename.(1)(revstart:revsize) is not a valid Matlab expression. I cannot guess reliably, what the purpose of this code is. filename seems to be a string containing the name of a file. Then .(1) is not a meaningful expression.
The contents of the file should be relevant, not its name. What kind of file is 'Dec20-1(cut4&2)_filter' ?
@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.
@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.

Sign in to comment.

Categories

Products

Release

R2022b

Asked:

on 16 Feb 2023

Commented:

on 18 Feb 2023

Community Treasure Hunt

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

Start Hunting!