MATLAB: Take value from vector as a relative column-based position for indexing to a corresponding matrix

indexingMATLABmatrix manipulationvectorizationvectors

Let's say we have a vector "a" with a range of numbers from 1 to 5, and is 100 elements in length.
a = randi([1 5],100,1)
Now, imagine that A(1)=3. I envision this to correspond to a relative position. Next, we introduce the matrix "B" which has the dimensions 100×5. 100 rows which correspond to the 100 rows in a, and 5 columns corresponding to the range of values encountered in a.
b=zeros(100,5)
What I want to do is use vectorized operations and say that b=b(1,*value from a(1)*)=1.
So if I wanted to display the first row of b, it would output
b(1,:) = 0 0 1 0 0
Other info-
I realize that this would be easily implemented using a for loop, and I realize that it would be very easy to do so. I am asking, is this possible to easily vectorize without having to give 5 separate conditional statements? That wouldn't scale well for larger datasets.
Thank you
Quick Edit-
It may be easier to think of this as an inverse max function. Imagine we have a vector of max locations, and we want to go back and kind of, back propagate a matrix of logical values.
ANSWER
I wanted to just edit the response with a simple, vectorized approach to this problem.
Since we know the range of values of a is from 1 to 5, we can confirm it through the use of unique:
unique(a) = 1 ; 2 ; 3 ; 4 ; 5
Next, lets say c= unique(a)
c = unique(a);
Lastly, to perform the logical indexing, it is simply:
b = c'==a;
This will produce a matrix with logical indexing at the relative positions.

Best Answer

I wanted to just edit the response with a simple, vectorized approach to this problem.
Since we know the range of values of a is from 1 to 5, we can confirm it through the use of unique:
unique(a) = 1 ; 2 ; 3 ; 4 ; 5
Next, lets say c= unique(a)
c = unique(a);
Lastly, to perform the logical indexing, it is simply:
b = c'==a;
This will produce a matrix with logical indexing at the relative positions. The transpose on c is more of a formality due to the difference in dimensions between c and a.