Info
此问题已关闭。 请重新打开它进行编辑或回答。
Subscript indices must either be real positive integers or logicals.
1 次查看(过去 30 天)
显示 更早的评论
Hi, I have this problem and i don't know why it appears:
??? Subscript indices must either be real positive integers or logicals.
Error in ==> SumaSin at 27 sin(1) = A(1)*sin(2*pi*f(1)*tt) + phi(1);
function [] = SumaSin()
fs = 44100;
dur=1;
N=2048;
tt = [0:(1/fs):dur-(1/fs)];
A = zeros(1,4);
A(1)=0.5;
A(2)=0.05;
A(3)=0.25;
A(4)=0.1;
phi = zeros(1,4);
phi(1)=0;
phi(2)=pi/2;
phi(3)=0;
phi(4)=pi;
sin = zeros(1,4);
f = zeros(1,4);
f(1) = fs/N*10;
f(2) = 2*fs/N*10;
f(3) = 3*fs/N*10;
f(4) = 4*fs/N*10;
sin(1) = A(1)*sin(2*pi*f(1)*tt) + phi(1);
sin(2) = A(2)*sin(2*pi*f(2)*tt) + phi(2);
sin(3) = A(3)*sin(2*pi*f(3)*tt) + phi(3);
sin(4) = A(4)*sin(2*pi*f(4)*tt) + phi(4);
sin = sin(1)+sin(2)+sin(3)+sin(4);
plot(tt,sin)
end
0 个评论
回答(1 个)
Iman Ansari
2013-5-8
Hi. Use another name for your variable 'sin'. When you use it as a variable,then you can't use it as sinusoid function:
fs = 44100;
dur=1;
N=2048;
tt = [0:(1/fs):dur-(1/fs)];
A = zeros(1,4);
A(1)=0.5;
A(2)=0.05;
A(3)=0.25;
A(4)=0.1;
phi = zeros(1,4);
phi(1)=0;
phi(2)=pi/2;
phi(3)=0;
phi(4)=pi;
f = zeros(1,4);
f(1) = fs/N*10;
f(2) = 2*fs/N*10;
f(3) = 3*fs/N*10;
f(4) = 4*fs/N*10;
s(1,:) = A(1)*sin(2*pi*f(1)*tt) + phi(1);
s(2,:) = A(2)*sin(2*pi*f(2)*tt) + phi(2);
s(3,:) = A(3)*sin(2*pi*f(3)*tt) + phi(3);
s(4,:) = A(4)*sin(2*pi*f(4)*tt) + phi(4);
s = s(1,:)+s(2,:)+s(3,:)+s(4,:);
plot(tt,s)
0 个评论
此问题已关闭。
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!