I keep getting the following error message: Execution of script Dummy as a function is not supported: C:\MusicalSoundAnalysis\Analysis\Dummy.m
Show older comments
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 Comments
Stephen23
on 19 Sep 2025
functio [lent,delt,tmax,T]=Dummy(nP,frq,fs)
^^ check the spelling
David Koenig
on 19 Sep 2025
Answers (1)
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 Comments
function [lent,delt,tmax,T]=Dummy(nP,frq,fs)
T = nP*(1/frq); % max argument of sawtooth s
delt=1/fs; % sampling interval s
fNy=fs/2; % Nyquist freq
t=0:delt:T-1/fs; % time grid for saw
tmax=t(end); % max is last element, cheaper than max()
lent=numel(t); % length() is dangerous, avoid
fprintf('For nP = %d length of t = %d\n',nP,lent)
fprintf('delt = %gs, max t = %gs\n',delt,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);
David Koenig
on 19 Sep 2025
dpb
on 19 Sep 2025
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...
Categories
Find more on Creating and Concatenating Matrices in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!