positive integer or logical error

  • Follow


How do I fix this error?

B=[0 1 0 0 1 1 0 0 0 1 1];
[row,column]=size(B);

for c=1:column;
    B(0)=-1;
    if B(c)==0;
    B(c)=B(c-1);
    end
    if B(c)==1 && B(c-1)==1;
    B(c)=-1;
    end
    if B(c)==1 && B(c-1)==-1;
    B(c)=1;
    end
end

X=(1:11);
subplot(3,1,2);
plot(X,B);

I'm getting the error: 

??? Attempted to access B(0); index must be a positive integer or logical.

Error in ==> binary_encoding at 27
    B(0)=-1;
0
Reply Dave 3/8/2010 4:08:05 AM

MATLAB doesn't allow zero-based indexing.  You need to start at 1.  1
is the first element index.  Also, no negative, or fractional, indices
are allowed.
0
Reply ImageAnalyst 3/8/2010 4:18:20 AM


1 Replies
364 Views

(page loaded in 0.044 seconds)

Similiar Articles:













7/26/2012 11:05:19 PM


Reply: