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

7 vues (au cours des 30 derniers jours)
Mahmoud Khadijeh
Mahmoud Khadijeh le 20 Sep 2022
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 commentaires
Stephen23
Stephen23 le 20 Sep 2022
"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
dpb
dpb le 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.

Connectez-vous pour commenter.

Réponses (1)

Harshit Gupta
Harshit Gupta le 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.
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:

Tags

Produits


Version

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by