I keep getting the following error message: Execution of script Dummy as a function is not supported: C:\Musical​SoundAnaly​sis\Analys​is\Dummy.m

5 ビュー (過去 30 日間)
the function is
functio [lent,delt,tmax,T]=Dummy(nP,frq,fs)
T = nP*(1/frq); % max argument of sawtooth s
h=1/fs; % sampling interval s
fNy=fs/2; % Nyquist freq
t = 0:1/fs:T-1/fs; % time grid for saw
tmax=max(t);
delt=t(2)-t(1); % sampling interval s
lent=length(t);
disp(['for nP = ' num2str(nP) ' length of t = ' num2str(lent)])
disp(['delt = ' num2str(delt) ' s, max t = ' num2str(tmax)])
and the caller is
frq=65.4064; % Hzn
nP=30;
fs = 1000; % sampling frequency Hz
[lent_p,delt_p,tmax_p,T_p]=Dummy(nP,frq,fs);
The response is
Execution of script Dummy as a function is not supported: C:\MusicalSoundAnalysis\Analysis\Dummy.m
Am I doing something stupid?
>> ver
-----------------------------------------------------------------------------------------------------
MATLAB Version: 9.14.0.2206163 (R2023a)
MATLAB License Number: 521792
Operating System: Microsoft Windows 11 Pro Version 10.0 (Build 26100)
Java Version: Java 1.8.0_202-b08 with Oracle Corporation Java HotSpot(TM) 64-Bit Server VM mixed mode
-----------------------------------------------------------------------------------------------------
MATLAB Version 9.14 (R2023a)
Simulink Version 10.7 (R2023a)
Control System Toolbox Version 10.13 (R2023a)
DSP System Toolbox Version 9.16 (R2023a)
Signal Processing Toolbox Version 9.2 (R2023a)
Symbolic Math Toolbox Version 9.3 (R2023a)
System Identification Toolbox Version 10.1 (R2023a)
>>

回答 (1 件)

dpb
dpb 2025 年 9 月 18 日
編集済み: dpb 2025 年 9 月 18 日
The function keyword is missing the final "n" so it won't be recognized; hence, MATLAB thinks Dummy.m is a script and not a function; hence the error when trying to pass arguments to it.
Try
function [lent,delt,tmax,T]=Dummy(nP,frq,fs)
T = nP*(1/frq); % max argument of sawtooth s
h=1/fs; % sampling interval s
fNy=fs/2; % Nyquist freq
t = 0:1/fs:T-1/fs; % time grid for saw
tmax=max(t);
delt=t(2)-t(1); % sampling interval s
lent=length(t);
disp(['for nP = ' num2str(nP) ' length of t = ' num2str(lent)])
disp(['delt = ' num2str(delt) ' s, max t = ' num2str(tmax)])
end
frq=65.4064; % Hzn
nP=30;
fs = 1000; % sampling frequency Hz
[lent_p,delt_p,tmax_p,T_p]=Dummy(nP,frq,fs);
for nP = 30 length of t = 458 delt = 0.001 s, max t = 0.457
Also Nota Bene the use of the end keyword. While not absolutely mandatory in a standalone m-file, it is certainly best practice to use it and would be needed here to separate it from the calling code.
  3 件のコメント
dpb
dpb 2025 年 9 月 19 日
Can be easy to overlook the obvious trivial detail thinking it has to be something deeper...outside eyes help.
Might go ahead and Accept an answer to show it has been solved to others if no other reason...

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeDigital Filtering についてさらに検索

製品


リリース

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by