## Attempted to access x(2); index out of bounds because numel(x)=1. But I'm using a matrix?

### mhowell (view profile)

on 4 May 2013
Latest activity Commented on by Pradeep Kumar R

on 25 Feb 2016

### Azzi Abdelmalek (view profile)

I'm just trying to execute a simple for loop, but I keep getting this error "Attempted to access x(2); index out of bounds because numel(x)=1.

Error in Quiz (line 11) x = x(i)" I don't understand what the error means. Any help would be appreciated!

```x = [22.5 45 67.5 90]
```
``` for i=1:4
x = x(i)
a = a(x)
c = c(x)
alpha = alpha(x)
mu(a,c)
end```

## Products

No products are associated with this question.

### Azzi Abdelmalek (view profile)

on 4 May 2013
Edited by Azzi Abdelmalek

### Azzi Abdelmalek (view profile)

on 4 May 2013

After one itteration

```for i=1:4
x = x(i)
```

the length of x becomes equal to 1, then x(2) does not exist

### Iman Ansari (view profile)

on 4 May 2013

Hi.

You change your x in first loop :

```x = x(i) ====> x=22.5
```

after this x became a number.

Iman Ansari

### Iman Ansari (view profile)

on 4 May 2013

Use another variable:

```y = [22.5 45 67.5 90]
y(2)
n = [1 3 5 7]
for i=1:4
x = y(i)
a = a(x)
c = c(x)
alpha = alpha(x)
mu(a,c)
end
```
mhowell

on 4 May 2013

Thanks!!!

### Pradeep Kumar R (view profile)

on 25 Feb 2016

what should i do if i get the same error while using a if loop inside a for to plot a wave

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

Play games and win prizes!

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