I keep getting the following error message: Execution of script Dummy as a function is not supported: C:\MusicalSoundAnalysis\Analysis\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)
>>
2 件のコメント
回答 (1 件)
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);
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
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 Exchange で Digital Filtering についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!