Info

La pregunta está cerrada. Vuélvala a abrir para editarla o responderla.

Error: Function definitions are not permitted in this context.

1 visualización (últimos 30 días)
Soobin Choi
Soobin Choi el 28 de Mayo de 2017
Cerrada: MATLAB Answer Bot el 20 de Ag. de 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')

Respuestas (1)

Star Strider
Star Strider el 28 de Mayo de 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.)

La pregunta está cerrada.

Productos

Community Treasure Hunt

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

Start Hunting!