MATLAB: True false results to be saved as a value

create vectorloopreplacestorewhilezeros

I have a vector, a = [1,0,1,1,1,0,0,0……]
I want to say that when a is true, or when the elements in a are equal 1, to make another vector correspond.
So if I wanted the true elements to correspond as .25, how can I make another vector that reads: b = [.25,0,.25,.25,.25,0,0,0…..,]?
I was thinking something along the lines below.
a = zeros(1,10)
b = zeros(size(a))
while a == 1
b = .25
end

Best Answer

Simplest would be to just multiply the logical vector by 0.25:
>> a = [1,0,1,1,1,0,0,0];
>> b = a*0.25
b =
0.25 0 0.25 0.25 0.25 0 0 0
A more complex but versatile solution would be to convert the logical values into linear indices:
>> c = [0,0.25];
>> c(a+1)
ans =
0.25 0 0.25 0.25 0.25 0 0 0