Info

Cette question est clôturée. Rouvrir pour modifier ou répondre.

Error: Function definitions are not permitted in this context.

1 vue (au cours des 30 derniers jours)
Soobin Choi
Soobin Choi le 28 Mai 2017
Clôturé : MATLAB Answer Bot le 20 Août 2021
I want to design raised cosine pulse modulation code but this error keep coming up.
function result = rcp(alpha, t, W)
Error: Function definitions are not permitted in this context.
My source code:
%rcp.m
function result = rcp(alpha, t, W)
%Raised cosine function in time domain
result = sinc(2*W*t).*cos(2*pi* alpha*W*t)./(1-16*alpha^2*W^2*t.^2);
%Command line
t=[-3:0.001:3];
plot(t,rcp(0.9999,t,1)) %alpha = 1, W = 1
hold on;
plot(t,rcp(0.5,t,1), '--r') %alpha = 0.5, W = 1
plot(t,rcp(0.25,t,1), ':') %alpha = 0.25, W = 1
legend('₩alpha=1','₩alpha=0.5','₩alpha=0.25')
ylabel('pulse amplitude')
xlabel('t/T')
axis([-3 3 -0.25 1])
grid on
title('Raised-cosine pulses in time domain')

Réponses (1)

Star Strider
Star Strider le 28 Mai 2017
Save your function ‘rcp’ to its own ‘.m’ file as ‘rcp.m’ in your MATLAB user path.
function result = rcp(alpha, t, W)
%Raised cosine function in time domain
result = sinc(2*W*t).*cos(2*pi* alpha*W*t)./(1-16*alpha^2*W^2*t.^2);
end
(Another option is to create a function with your main code, since function definitions are permitted within other functions. The terminating end call is necessary in that instance.)

Cette question est clôturée.

Produits

Community Treasure Hunt

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

Start Hunting!