Hi, I am currently having difficulty with vectorizing a for loop. The purpose of the the loop is to iterate through column vector A and output 1 to empty column vector B if the element in A is greater than some scalar, and 0 otherwise. So far I have:
count = 1;for len = 2:length(filteredArray) + 1 if filteredArray(count) > inputScalar tempVector(count) = 1; count = count + 1; elseif filteredArray(count) <= inputScalar tempVector(count) = 0; count = count + 1; endend
This works fine, but I have no idea how to vectorize it for better efficiency. I thought about
x = filteredArray(1):1:length(filteredArray) + 1;tempVector(x) = (filteredArray(x) > inputScalar);
But I don't know how to work in the other condition and the outputs into a new vector. Help would be appreciated and thank you.
Best Answer