Info
此问题已关闭。 请重新打开它进行编辑或回答。
Error: Function definitions are not permitted in this context.
1 次查看(过去 30 天)
显示 更早的评论
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')
0 个评论
回答(1 个)
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.)
0 个评论
此问题已关闭。
另请参阅
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!