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

조회 수: 25 (최근 30일)
Mahmoud Khadijeh
Mahmoud Khadijeh 2022년 9월 20일
답변: Harshit Gupta 2022년 10월 4일
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
Stephen23
Stephen23 2022년 9월 20일
"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 2022년 9월 21일
"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.

댓글을 달려면 로그인하십시오.

답변 (1개)

Harshit Gupta
Harshit Gupta 2022년 10월 4일
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:

카테고리

Help CenterFile Exchange에서 Startup and Shutdown에 대해 자세히 알아보기

태그

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by