MATLAB: Element wise logical operators

multi dimensional array element wise manipulation

I have a question regarding using logical operators on a multi-dimensional array.
I want to firstly test if an element passes a criteria then replace that value with another value given the results of a test.
I want to check the first dimension of the array against the threshold of 0.5 and replace all instances where this is true with a value for only 2 columns of the the 2nd dimension and all cases of the 3rd and 4th dimension. Does anyone know how to do this without multiple for loops?
for example
DA = rand(4,4,2,3);
if DA(:,2:4,:,:)<0.5;
DA(:,2:4,:,:) = 1;
end
thanks Tim

Best Answer

clear
DA = rand(4,4,2,3);
K=arrayfun(@(x) x<0.5,DA(:,2:4,:,:))
B=DA(:,2:4,:,:);
B(find(K==1))=1;
DA(:,2:4,:,:)=B