Error: Function definitions are not permitted in this context.

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')

답변 (1개)

Star Strider
Star Strider 2017년 5월 28일
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.)

이 질문은 마감되었습니다.

제품

질문:

2017년 5월 28일

마감:

2021년 8월 20일

Community Treasure Hunt

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

Start Hunting!