-3

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?

NikolaC
  • 5
  • 5
  • You need to show some code and clarify your question. As it is written this question should be closed as it is not providing a clear example of the problem – PyNEwbie Nov 23 '15 at 14:29
  • number_tags= 10. a want to create 10 vectors with 8 bits. Also I want to randomly choose number 1 in each tag. For example: Tag1 = [00100000]; Tag2 = [00000100]; Tag3 = [01000000]; – NikolaC Nov 23 '15 at 14:31
  • How about you create a [random integer](http://nl.mathworks.com/help/stats/random.html) and [turn it into a binary number](http://nl.mathworks.com/help/fixedpoint/ref/bin.html) – Johannes Nov 23 '15 at 14:34
  • I can not do it. If you can write a code – NikolaC Nov 23 '15 at 14:39

1 Answers1

0

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;
Mikhail_Sam
  • 10,602
  • 11
  • 66
  • 102