For logical comparisons, it should be == instead of =
if(b(n) == 1)
Also, for your last question, use the sum command and indexing "sum(X(1:d))". Type "doc sum" at the command line to make sure you know how to use it. Also, read some of the help files on the colon operator and array and logical indexing. For your code below, there are much faster ways to arrive at the same result using vectorization techniques and logical indexing. It doesn't really matter if d equals 5, but when you get into the thousands and beyond it makes a substantial difference.
Hope this helps,
Travis
"Alex" <a.shan@hotmail.co.uk> wrote in message <gs24aq$3cu$1@fred.mathworks.com>...
> Hi im getting an error for the following but i dont know what im doing wrong
>
> d = 5
> b = 1 0 0 1 1
> mfile:
> for n = 1:d
> if(b(n) = 1) error on this line
> X(n) = 1
> else
> X(n) = 1
> end
> end
>
> Also if I want to do the sum of X from 1 to d how would I do this
>
> Thanks
