You need to create a logical index (a "map") first of where A is less than its median. Then use that logical index to make the assignment
A = rand(10, 60, 1200); % Create sample data.
median_A = median(A(:))
max_A = max(A(:))
min_A = min(A(:))
% Find where A is less than it's median.
logicalIndexes = A <= median_A; % A 3-D logical array.
% First initialize everything:
anomaly = ((median_A - A)./(max_A - median_A)*100);
% Make up second set of numbers.
A2 = ((median_A - A)./(median_A - min_A)*100);
% Then replace only those indexes where A(i,j,k) < median_A
anomaly(logicalIndexes) = A2(logicalIndexes);
Also, look up the mad() and isoutier() functions.
