## Subscript indices must either be real positive integers or logicals.

### Jordi (view profile)

on 8 May 2013

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
```

## Tags

No tags are associated with this question.

## Products

No products are associated with this question.

### Iman Ansari (view profile)

on 8 May 2013

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

#### Join the 15-year community celebration.

Play games and win prizes!

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi