Execution of script findpeaks as a function is not supported: Problem?

Hello,
I have a problem during execting a very simple function "findpeaks".
I'm trying to excute the following script from MATLAB Documentsions:
data = [25 8 15 5 6 10 10 3 1 20 7];
plot(data)
pks = findpeaks(data)
However, I'm getting the following error:
Execution of script findpeaks as a function is not supported:
\My Documents\MATLAB\findpeaks.m
Error in untitled (line 4)
pks = findpeaks(data)
Any help on how to solve this problem!

6 Comments

hello
your path to the findpeaks function seems strange to me , as if you had copied / pasted onky that function to your corresponding working directory
If you hae the signal processing toolbox installed , the path should be like :
C:\Program Files\MATLAB\R2020b\toolbox\signal\signal\
what is your installed version ? (type ver at the command window)
If you don't have the signal processing toolbox and you just copied this function only, it will not work
Alternatives to findpeaks are available (look in the FEX section) , like the one in attachement
Actually, the same code works fine on an old version (MATLAB R2016a)
But when I used MATLAB 2021b.
I got this problem
Don't name your script FINDPEAKS.
I tried different names and the problem still the same.
It seems that this is only on the MATLAB version of my computer in my university.
When I tried that on other computers, it works fine!
"It seems that this is only on the MATLAB version of my computer in my university. "
The error message already tells us where the problem is:
\My Documents\MATLAB\findpeaks.m
Once you rename your files, you might also need to
rehash toolboxcache
"Once you rename your files, ..."
And, if you did the renaming by copying to another filename, you'll also have to delete the old
\My Documents\MATLAB\findpeaks.m
copy...if it's still around, even if execute the new script, it'll try to call that old one instead of the Toolbox version.
Show us what
which -all findpeaks
returns on your machine -- then for elucidation, compare that to the other machine/installation that works as expected.

Sign in to comment.

Answers (1)

As per my understanding, you are trying to execute “findpeaks” function which gives the following error-
Execution of script findpeaks as a function is not supported.
The common causes for the same are listed as follows:
  1. You have created a script MATLAB file with the same name as a function on the MATLAB path but higher on the path than that function.
  2. You are attempting to index into an array that does not exist when a script file with that name exists.
Solution:
Execute
>> which -all filename
for the file specified in the error message. Verify that the file you expect to execute is being used instead of any other file with the same name. If it is not, rename or delete the files higher on the MATLAB path than the file you expect to use, or reorder the directories on your MATLAB path to place the version of the file you want to use higher than any other version.
To check whether your filename conflicts with the in-built functions, you can use “exist” command on the command prompt. The documentation for the same is given in the following link:

Categories

Products

Release

R2021b

Tags

Asked:

on 20 Sep 2022

Answered:

on 4 Oct 2022

Community Treasure Hunt

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

Start Hunting!