You could also re-arrange the indices and move the for loop to the last 
index

function f(n)
    A = rand(n, n, 3) 
    S = rand(n, n) 
    for k = 1:size(A, 3) 
        A[:,:,k] = A[:,:,k] ./ S 
    end 
    return A 
end

This works since A[:,:,k] is a 2-d array but A[k,:,:] is a 3-d array.
​

Reply via email to