Generate a matrix of 1 and 0
Show older comments
I want to generate a matrix B of 1's and 0's corresponding to a vector A of Integers.
For Example if A =[4 5 3 2 4 2 1 4]; is my allocation vector which represents that thing 1,5,8 are assigned to user 4, 2 is assigned to user 5, 3 to user 3, 4, 6 to user 2 and 7 to user 1.
Now i want to generate a Matrix which will have users as columns and thing assigned as rows (or opposite), if a thing is assigned to that user it will have an entry 1 that particular row if it is not assigned that it will have a entry zero in that row. Thus B user,thing =1 or 0. that is B4,1 B4,5 B4,8 are 1 and B4,2 B4,3 B4,4 B4,6 B4,7 are zero. How to do this in MATLAB
1 Comment
Matt Fig
on 23 Aug 2012
Your explanation is very hard to follow. Please show a simple example that has BOTH the input AND the output.
A = [4 5 3 2 4 2 1 4];
B = ??? SHOW THIS
Accepted Answer
More Answers (1)
Image Analyst
on 23 Aug 2012
Edited: Image Analyst
on 23 Aug 2012
How about
B = A==4
Gives:
B =
1 0 0 0 1 0 0 1
or
B = find(A==4);
Gives:
B =
1 5 8
Categories
Find more on Mathematics 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!