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

47 views (last 30 days)
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];
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!
dpb on 21 Sep 2022
"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)

Harshit Gupta
Harshit Gupta on 4 Oct 2022
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.
>> 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:





Community Treasure Hunt

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

Start Hunting!

Translated by