xor operation using loop

3 views (last 30 days)
Urmila
Urmila on 24 Feb 2014
Commented: Urmila on 24 Feb 2014
i have 1 dimentional array say p=[1 0 1 0 1 1 1 0 0], now i want to xor its bits like
Q(l)= xor(p(i))...... where i=l,l+N,l+2n,l+3N...........upto i<10 And N=2 and 1<l<N
How to implement it in loop i dont understand..plz help me kindly
  2 Comments
Mischa Kim
Mischa Kim on 24 Feb 2014
Edited: Mischa Kim on 24 Feb 2014
Urmila, for logical operations you typically need two inputs, e.g., xor(1,0). In your example xor(p(i)) it looks like you only have one (at a time). Do you mean
Q(l) = xor(p(i),p(l))
Urmila
Urmila on 24 Feb 2014
my meaning of p(i) is p(1),p(3),p(5)...upto i<10 according to the equation. so how to take those particular bits for xoring..

Sign in to comment.

Accepted Answer

Azzi Abdelmalek
Azzi Abdelmalek on 24 Feb 2014
p=[1 0 1 0 1 1 1 0 0]
po=p(1:2:end)
out=po(1)
for k=2:numel(po)
out=xor(out,po(k))
end

More Answers (0)

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!