Could you help me? I have n = 10 (ten tags) with 8 bits value each. Every tag should have one randomly created 1's in ID (for example 00000100, 01000000). How can I do this in Matlab?
Let's try this:
n = 10;
r = 8;
k = randi(r,1,n);
Tag = zeros(r,n);
Tag(r*(find(k)-1) + k)=1;
Tag = Tag';
So:
k =
8 8 5 2 2 3 7 3 7 2
Tag =
0 0 0 0 0 0 0 1
0 0 0 0 0 0 0 1
0 0 0 0 1 0 0 0
0 1 0 0 0 0 0 0
0 1 0 0 0 0 0 0
0 0 1 0 0 0 0 0
0 0 0 0 0 0 1 0
0 0 1 0 0 0 0 0
0 0 0 0 0 0 1 0
0 1 0 0 0 0 0 0
Now each row - your Tag. For example, Tag1 = Tag(1,:)
.
In this case lets find needed result: if we need only logical values (1 if there is 1 in any row, and 0 if there is no any 1 in column) we have to add this:
result = sum(Tag);
result(find(result))=1
result =
0 1 1 0 1 0 1 1
Number of ones and zeros:
c1 = sum(result);
c0 = numel(result) - c1;