Info

この質問は閉じられています。 編集または回答するには再度開いてください。

Error: Function definitions are not permitted in this context.

1 回表示 (過去 30 日間)
Soobin Choi
Soobin Choi 2017 年 5 月 28 日
閉鎖済み: MATLAB Answer Bot 2021 年 8 月 20 日
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.)

この質問は閉じられています。

製品

Community Treasure Hunt

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

Start Hunting!