I have a vector
V=[ 1 2 3 5 9];
and would like to multiply it like this:
newVect=zeros(1,length(V));
for i=1:length(V)
if V(i)==1
newVect(i)=V(i)*somevaluex
elseif V(i)==5
newVect(i)=V(i)*somevaluey
else
newVect(i)=V(i);
end
This seems cumbersome as I’m actually dealing with arrays with 10000 elements. Can this be replaced by vectorisation somehow?
You can do that:
or a bit faster: